我找到了一个包含所有国家/地区数据的KML文件,它非常适合作为叠加层,我在KML文件中发布了一个国家/地区的示例 - 我的问题是:
我使用suppressInfoWindows: true
关闭了信息窗口当用户点击地图时,如何将描述标记内容作为var?我知道点击事件部分我只需要知道如何从kml获取信息。
<Placemark><name>Aruba</name><description>ISO_A2=AW</description><LookAt><longitude>-69.98267466267889</longitude><latitude>12.52088880763951</latitude><heading>10.0</heading><tilt>10.0</tilt><range>700</range></LookAt><Style><IconStyle><color>00ffffff</color><scale>0.4</scale><Icon><href>http://icons.opengeo.org/markers/icon-poly.1.png</href></Icon></IconStyle><LabelStyle><color>00ffffff</color></LabelStyle><PolyStyle><color>ffD0D1E6</color><outline>1</outline></PolyStyle><LineStyle><color>ff000000</color><width>1</width></LineStyle></Style><MultiGeometry><Point><coordinates>-69.98267466267889,12.52088880763951</coordinates></Point><Polygon><outerBoundaryIs><LinearRing><coordinates>-69.89913876,12.45200511 -69.89567644,12.42301463 -69.94215939,12.43851756 -70.00414527,12.50050344 -70.06613115,12.5469864 -70.05086077,12.5970867 -70.03512529,12.61411408 -69.97313941,12.56763113 -69.91179949,12.48047883 -69.89913876,12.45200511</coordinates></LinearRing></outerBoundaryIs></Polygon></MultiGeometry></Placemark>
答案 0 :(得分:1)
解决它,以防万一其他人想知道你将监听器添加到kml然后在click事件上使用featureData - 就像这样
kml = new google.maps.KmlLayer( “HTTP://whatever/countries_world.kml”,{suppressInfoWindows: 真正});
kml.setMap(地图);
google.maps.event.addListener(kml,'click', 功能(e){alert(e.featureData.name);
}); }