Google Maps API V3:KML图层没有显示?

时间:2013-04-22 18:31:09

标签: javascript google-maps-api-3 kml

我有一个KML文件,我将其复制/粘贴在一起,形成如下所示的融合表:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
<Document>
<Polygon><outerBoundaryIs><LinearRing><coordinates>-73.992177,40.743465,0.0 -74.008242,40.752352,0.0 -74.006533,40.756112,0.0 -73.983973,40.748934,0.0 -73.987733,40.744149,0.0 -73.992177,40.743465,0.0</coordinates></LinearRing></outerBoundaryIs></Polygon>
<Polygon><outerBoundaryIs><LinearRing><coordinates>-73.973035,40.689458,0.0 -73.989784,40.683305,0.0 -74.008242,40.686381,0.0 -73.978846,40.705181,0.0 -73.977479,40.698003,0.0 -73.973035,40.689458,0.0</coordinates></LinearRing></outerBoundaryIs></Polygon>
(...)
</Document>
</kml>

据我所知,在地图上绘制这些内容就像

一样简单
var zipoverlay = new google.maps.KmlLayer('zips.kml');
zipoverlay.setMap(map);

但显然这没有任何作用。它不像我想象的那么神奇吗?

谢谢!

4 个答案:

答案 0 :(得分:8)

感谢Dr.Molle,我们想出了这一点。这就是我做错了:

  1. 需要从我自己的机器外部访问KML文件。在其他地方托管它,以便地图能够抓住它
  2. KML文件的结构必须如下:
  3. `

    <?xml version="1.0" encoding="UTF-8"?>
    <kml xmlns="http://earth.google.com/kml/2.2">
    <Document>
    <Placemark>
    <Polygon><outerBoundaryIs><LinearRing><coordinates>-73.992177,40.743465,0.0 -74.008242,40.752352,0.0 -74.006533,40.756112,0.0 -73.983973,40.748934,0.0 -73.987733,40.744149,0.0 -73.992177,40.743465,0.0</coordinates></LinearRing></outerBoundaryIs></Polygon></Placemark>
    <Placemark><Polygon><outerBoundaryIs><LinearRing><coordinates>-73.973035,40.689458,0.0 -73.989784,40.683305,0.0 -74.008242,40.686381,0.0 -73.978846,40.705181,0.0 -73.977479,40.698003,0.0 -73.973035,40.689458,0.0</coordinates></LinearRing></outerBoundaryIs></Polygon>
    </Placemark>
    </Document></kml>
    

答案 1 :(得分:0)

<Polygon/>必须是<Placemark/><MultiGeometry/>的孩子,而不是<Document/>

的孩子

答案 2 :(得分:0)

我的错误是在我的服务器上启用了HTTP身份验证,这阻止了Google请求KML文件。我想这不是客户端。

答案 3 :(得分:0)

我遇到了此类问题(kml层未显示),因为网址(或可能只是文件名)太长。 使用较短的网址即可正常工作。