Google Map KML layer placemark click event return ZERO_RESULTS

折月煮酒 提交于 2020-01-01 09:09:31

问题


Attaching listener to KML layer:

var layer = new google.maps.KmlLayer('http://sites.google.com/site/kmlprototypes/kmls/temp.kml?dc_=' + Math.random(),
{suppressInfoWindows:true,preserveViewport:true});

layer.setMap(map);

google.maps.event.addListener(layer, 'click', function (obj) {
    alert(obj.featureData.id);
});

KML file is valid (checked by validation api), you may find it here. Each placemark in XML has id attribute like:

<Placemark id="46">
  <Style>
    <IconStyle>
      <Icon>
        <href>
          <![CDATA[http://chart.apis.google.com/chart?chf=bg,s,EAF7FE02&chxt=y&chbh=a,4,4&chs=48x48&cht=bvg&chco=FF0000,0000FF&chds=20,9048.00,0,9048.00&chd=t:8149.00|9048.00]]>
        </href>
      </Icon>
    </IconStyle>
  </Style>
  <Point>
    <coordinates>30.49566650390625,50.721378326416016</coordinates>
  </Point>
</Placemark>

When clicking on a placemark in google map object returns right id, but sometimes about 50% of the time obj.featuredData.id is null (ZERO_RESULTS status is in status field). I have tried different sets of data (form 100 points to 1000), but it doesn't help. Also I've tried different precisions for lat, lng.


回答1:


You've probably hit one the limits listed on that page: https://developers.google.com/kml/documentation/mapsSupport?hl=en

Maximum 1000 features per file could be the one that is bothering you.



来源:https://stackoverflow.com/questions/11775801/google-map-kml-layer-placemark-click-event-return-zero-results

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!