【问题标题】:Google Map KML layer placemark click event return ZERO_RESULTSGoogle Map KML 图层地标点击事件返回 ZERO_RESULTS
【发布时间】:2012-07-31 07:49:53
【问题描述】:

将监听器附加到 KML 层:

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 文件有效(通过验证 api 检查),您可能会发现它here。 XML 中的每个地标都有 id 属性,例如:

<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>

当点击谷歌地图对象中的地标时返回正确的 id,但有时大约 50% 的时间obj.featuredData.idnullZERO_RESULTS 状态在status 字段中)。我尝试了不同的数据集(从 100 点到 1000 点),但没有帮助。我还尝试了 lat、lng 的不同精度。

【问题讨论】:

  • 只有custom markers (the "charts") 有问题吗?
  • 您的 KML 似乎包含太多自定义标记。 Here 它是使用 geoxml3 渲染的(需要一段时间才能渲染)。如果隐藏这些标记(单击隐藏按钮),然后显示 KmlLayer,您会看到默认蓝色标记和自定义标记的组合。

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


【解决方案1】:

您可能已经达到了该页面上列出的限制之一:https://developers.google.com/kml/documentation/mapsSupport?hl=en

每个文件最多 1000 个功能可能是困扰您的一个。

【讨论】:

    猜你喜欢
    • 2013-01-05
    • 2013-06-04
    • 1970-01-01
    • 2013-02-04
    • 1970-01-01
    • 2012-02-19
    • 2016-06-21
    • 2015-06-24
    • 1970-01-01
    相关资源
    最近更新 更多