每个标记的不同kml文件

时间:2015-06-30 07:29:36

标签: javascript google-maps google-maps-markers

我是谷歌地图javascript api的新手。我已经阅读了一些教程,我遇到了一个问题,我无法找到答案。 您可以使用kml文件中的Feed来显示同一kml文件中的一个或多个标记,如下所示:

var ctaLayer = new google.maps.KmlLayer({
  url: 'http://gmaps-samples.googlecode.com/svn/trunk/ggeoxml/cta.kml'
});

但是有没有办法代表每个kml文件,一个标记?

2 个答案:

答案 0 :(得分:2)

To load multiple KML files you need to instantiate multiple KmlLayer objects. The content of the KML (which could be a single marker) will be rendered on your map (assuming you add it to the map, which your posted code doesn't).

Note that there used to be a documented limitation on the number of KmlLayers you could add to a map (based on the URLs of the KML files). I no longer see that in the documentation, but that doesn't mean it doesn't still exist.

var layer1 = new google.maps.KmlLayer({
  url: 'http://gmaps-samples.googlecode.com/svn/trunk/ggeoxml/cta.kml'
});

var layer2 = new google.maps.KmlLayer({
  url: 'http://gmaps-samples.googlecode.com/svn/trunk/ggeoxml/another.kml'
});

答案 1 :(得分:0)

这是带有标记

的KML的代码
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
<Document>
    <name>test.kml</name>
    <Placemark>
        <name>test</name>
        <Point>
            <coordinates>19.946565112231001,48.0076404070977,0</coordinates>
        </Point>
    </Placemark>
</Document>
</kml>