1

I am trying to display some markers on a Google Map using an XML file.

I seem to be able to get the markers to display OK but I want to know how I can filter them down.

The XML in question is like the below;

    <?xml version="1.0" encoding="utf-16"?>
<OutageData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <TimeStamp>2014-01-24T11:33:41.665165+00:00</TimeStamp>
  <Outages>
    <Outage>
      <Region>South West</Region>
      <IncidentID>INCD-30315-k</IncidentID>
      <ConfirmedOff>4</ConfirmedOff>
      <PredictedOff>0</PredictedOff>
      <Restored>0</Restored>
      <Status>In Progress</Status>
      <Planned>false</Planned>
      <StartTime>2014-01-24T09:30:00</StartTime>
      <ETR xsi:nil="true" />
      <Voltage>LV</Voltage>
      <PostCodes>
        <string>TR20 8UJ</string>
      </PostCodes>
      <Sensitive>0</Sensitive>
      <Location lat="50.13206" lng="-5.5528" />
    </Outage>
    <Outage>
      <Region>South West</Region>
      <IncidentID>INCD-30342-k</IncidentID>
      <ConfirmedOff>7</ConfirmedOff>
      <PredictedOff>0</PredictedOff>
      <Restored>0</Restored>
      <Status>In Progress</Status>
      <Planned>true</Planned>
      <StartTime>2014-01-24T09:00:00</StartTime>
      <ETR xsi:nil="true" />
      <Voltage>LV</Voltage>
      <PostCodes>
        <string>TR4 8AL</string>
        <string>TR4 8AN</string>
        <string>TR4 8AP</string>
        <string>TR4 8AW</string>
        <string>TR4 8FE</string>
      </PostCodes>
      <Sensitive>4</Sensitive>
      <Location lat="50.28881" lng="-5.236961" />
    </Outage>
</Outages>
</OutageData>

However I only want to display markers where the Planned value is 'false'. So from the data above, only one marker should show on the map.

The code I am currently using is jQuery code;

jQuery.get("/dataNew.xml", {}, function (data) {
        jQuery(data).find("Outage").each(function () {

                $(this).find("Location").each(function () {
                    var marker = jQuery(this);
                    var latlngNew = new google.maps.LatLng(parseFloat(marker.attr("lat")),
                                            parseFloat(marker.attr("lng")));
                    var marker = new google.maps.Marker({ position: latlngNew, map: map });
                });

        });
    });

If anyone is able to point me in the right direction I would be most appreciative.

Kind regards,

Chris

1 Answer 1

1

If you get the value of the planned node each time in an if you can simply stop the plotting of points you don't want. Something like: (untested)

jQuery.get("/dataNew.xml", {}, function (data) {
    jQuery(data).find("Outage").each(function () {
            if($(this).find("Planned").text() == "true")
            {
                $(this).find("Location").each(function () {
                    var marker = jQuery(this);
                    var latlngNew = new google.maps.LatLng(parseFloat(marker.attr("lat")),
                                           parseFloat(marker.attr("lng")));
                    var marker = new google.maps.Marker({ position: latlngNew, map: map });
                });
            }

    });
});
1
  • I think I managed to get it going a similar way, but by creating the 'Planned' statement as a variable and adding this to the 'if' statement. This solution works just as well. Thank you for your help. Jan 24, 2014 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.