Skip to content Skip to sidebar Skip to footer

Parse Xml File With Javascript And Plot On Google Maps

Note: I am self taught (i.e. Google), so if my questions and explanations are silly/simple that is probably why. I'm a server guy, and have never done this type of scripting (pul

Solution 1:

I believe I've found at least a parital answer to my original question. The code below will extract the coordinates from my xml file. From here, I will need to plot it out. It's tough being a newbie sometimes.

functionmyFunction(xml) {
        var x, y, i, xmlDoc, latLng;
        xmlDoc = xml.responseXML;
        x = xmlDoc.getElementsByTagName('latitude');
        y = xmlDoc.getElementsByTagName('longitude');
        for (i = 0; i < x.length; i++) { 
            latLng = x[i].childNodes[0].nodeValue + y[i].childNodes[0].nodeValue;
        }
    }

Solution 2:

Here is my final code snippet that works.

   function PlotUm(xml) {
   var x, y, i, txt, xmlDoc, latLng;
   xmlDoc = xml.responseXML;
   x = xmlDoc.getElementsByTagName('latitude');
   y = xmlDoc.getElementsByTagName('longitude');alert("FOR LOOP");
   for (var i = 0; i < x.length; i++)  {
        xcoord = x[i].childNodes[0].nodeValue;
        ycoord = y[i].childNodes[0].nodeValue;
        var latLng = new google.maps.LatLng(xcoord,ycoord);
        var marker = new google.maps.Marker({
             position: latLng,
             icon: 'http://maps.google.com/mapfiles/ms/micons/pink.png',
             map: map
        });
   }
}

Post a Comment for "Parse Xml File With Javascript And Plot On Google Maps"