Is there a way to get marker information from this style of XML/KML document ?

<?xml version="1.0" encoding="UTF-8" ?>
 <kml xmlns="http://earth.google.com/kml/2.2">
   <Document>
    <Placemark>
        <Point>
            <coordinates>4.4852,51.52229,0</coordinates>
        </Point>
    </Placemark>
   </Document>
</kml>

Now we need to change the gps coordinates so the useable format for us should be: 51.52229,4.4852.

How to load this gps coordinates in a variable and put them in our map in V3 code. We have tryed this code but it doesnt work.

 // Stormchasers locaties inladen  
 downloadUrl("https://www.followmee.com/kml.aspx?token=b327299e-33e7-4b56-96ef-88d812544686", function(data) {

var xml = xmlParse(data);

var markers = xml.documentElement.getElementsByTagName("Point");

var bounds = new google.maps.LatLngBounds();

for (var i = 0; i < markers.length; i++) {

  var path = [];

  var points = markers[i].getElementsByTagName("coordinates");

    path.push(point);

    var marker = createMarker(latlng);

    marker.setMap(map); 

}



 }); 

 function createMarker(latlng) {
 var marker = new google.maps.Marker({
map: map,
position: latlng,
});
return marker;
 }
 // Einde Iconen inladen

Could someone help us ?

Thank you!

有帮助吗?

解决方案

geoxml3 parses KML coords, the code below was extracted from the processPlacemarkCoords function. Since you only have single sets of coordinates, in your example, you can do this (point will be a google.maps.LatLng object with the desired coordinates), if you need to handle polylines or polygons, you will need to do more.

    var coords = geoXML3.nodeValue(coordNodes[j]).trim();
    coords = coords.replace(/,\s+/g, ',');
    coords = coords.split(',');
    if (!isNaN(coords[0]) && !isNaN(coords[1])) {
    var point = new google.maps.LatLng(
        parseFloat(coords[1]), 
        parseFloat(coords[0]))
    } else alert("bad coordinates, not numbers");


//nodeValue: Extract the text value of a DOM node, with leading and trailing whitespace trimmed
geoXML3.nodeValue = function(node, defVal) {
  var retStr="";
  if (!node) {
    return (typeof defVal === 'undefined' || defVal === null) ? '' : defVal;
  }
   if(node.nodeType==3||node.nodeType==4||node.nodeType==2){
      retStr+=node.nodeValue;
   }else if(node.nodeType==1||node.nodeType==9||node.nodeType==11){
      for(var i=0;i<node.childNodes.length;++i){
         retStr+=arguments.callee(node.childNodes[i]);
      }
   }
   return retStr;
};
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top