Google maps 如何从KML文件中获取坐标?

Google maps 如何从KML文件中获取坐标?,google-maps,google-maps-api-3,kml,Google Maps,Google Maps Api 3,Kml,有没有办法解析kml文件并用JavaScript从中获取坐标 我已经尝试过像使用getElementsByTagName一样使用它,但调试器说它不是有效的函数 有什么想法吗 这并不容易,但您可以导入文件xml并使用jquery parseXML进行解析 // import the file --- se related function below var content = getSelectedFileContent(importFilename); // buil

有没有办法解析kml文件并用JavaScript从中获取坐标

我已经尝试过像使用getElementsByTagName一样使用它,但调试器说它不是有效的函数


有什么想法吗

这并不容易,但您可以导入文件xml并使用jquery parseXML进行解析

    // import the file --- se related function below
    var content = getSelectedFileContent(importFilename);

    // build an xmlObj for parsing
    xmlDocObj = $($.parseXML(content));


function getSelectedFileContent(filename) { 
    // var importFilename = importAreaBaseURL + filename;
    var request = new XMLHttpRequest();
        request.open("GET", filename, false);
        request.send(null);
        return request.responseText;
};
此时,您可以轻松地解析placemark的xml obj,并通过jquery对其进行迭代以获得所需的标记/值

var placemarks = xmlDocObj.find("Placemark");
        placemarks.each(function (index) {

                if ($(this).find("Polygon").length > 0) {
                    tipoGeom = "Polygon";
                    tmpHtml = $(this).find("Polygon").find("outerBoundaryIs").find("coordinates").html();
                    gmlll_geom =  kmlCoords2gmlll( tmpHtml);

                    inner = $(this).find("Polygon").find("innerBoundaryIs");
                    inner.each(function(index,el) {
                       $(el).find("coordinates").html(); // this are the coordinates for polygion 
                    });


                }
            });
这些是功能代码的摘录样本部分。。。。您所需要的这些代码并不仅仅是一个建议