admin管理员组

文章数量:1291595

I have a KML file that I copy/paste together form a fusiontable which looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns=".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>

As far as I understand drawing these on the map is as easy as

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

But apparently this does nothing. Is it not as magical as I thought?

Thanks!

I have a KML file that I copy/paste together form a fusiontable which looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google./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>

As far as I understand drawing these on the map is as easy as

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

But apparently this does nothing. Is it not as magical as I thought?

Thanks!

Share Improve this question asked Apr 22, 2013 at 18:31 Paul RiedelPaul Riedel 4193 gold badges8 silver badges19 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 9

Thanks to Dr.Molle we figured this out. Here's what I did wrong:

  1. The KML file needs to be accessible from outside my own machine. Host it somewhere else in order for maps to be able to grab it
  2. The structure of the KML file needs to be like this:

`

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google./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>

A <Polygon/> has to be a child of either <Placemark/> or <MultiGeometry/>, but not of <Document/>

My mistake was having HTTP auth enabled on my server, which was preventing google from requesting the KML file. I guess it is not done client side.

I had this kind of issue (kml layer not displaying) because the url (or maybejust the file name) was too long. With a shorter url it was working.

本文标签: javascriptGoogle Maps API V3 KML Layer not showingStack Overflow