Skip to content Skip to sidebar Skip to footer

How To Parse Xml File For Marker Locations And Plot On Map

I am trying to read points from an xml file rather than from javascript as in the example below. https://google-developers.appspot.com/maps/documentation/javascript/examples/mark

Solution 1:

Brilliant - thanks a lot for the hint! One little mistake is still in the above code:

replace

markers.setMap(map);

by

marker.setMap(map);

...then it'll work!

Solution 2:

I use jQuery both to get the XML file and then to parse it. I've used this approach many times but don't have time to test this, so there may be syntax errors.

<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> 
...
var map;
functioninit() 
{
    map = new google.maps.Map("map_canvas");
    jQuery.get("companies.xml", {}, function(data) {
        jQuery(data).find("company").each(function() {
            var company = jQuery(this);
            var lat = jQuery(company).find("lat").text();
            var lon = jQuery(company).find("lng").text();
            var latlng = new google.maps.LatLng( parseFloat(lat), parseFloat(lon) );
            var marker = new google.maps.Marker( { position: latlng, }); 
            markers.setMap(map);
        }); 
    }); 
}

Post a Comment for "How To Parse Xml File For Marker Locations And Plot On Map"