我正在检索 Google Earth .kml (xml) 文件并使用该内容在 Google 地图中放置标记。
我感兴趣的特定 XML 标签如下所示:
<Placemark>
<name>Bahamas-LSI</name>
<description><![CDATA[
<img src="http://coralreefwatch.noaa.gov/satellite/ge/data/current/vs_Bahamas_LSI.bmp">
<p>
- <a href="http://coralreefwatch.noaa.gov/satellite/virtual_stations/greater_caribbean.html#Bahamas_LSI">
SST/DHW time series</a>.
<p>
- E-mail [email protected] /cdn-cgi/l/email-protection to subscribe free<br>automatic e-mail bleaching alert for this site.
]]></description>
<Snippet></Snippet>
<LookAt>
<longitude>-76.5000</longitude>
<latitude>23.5000</latitude>
..
</Placemark>
以下代码提取名称和经纬度,但是我不知道如何使用 jQuery 从描述标签中提取 CDATA。我希望能够提取实际的 html,以便我可以在 Google 地图标记的信息窗口中使用它。
//
jQuery.get("CRWGE_current_products.kml", {}, function(data) {
// for each placemark tag, extract the name & latlong
// and then plot
jQuery(data).find("placemark").each(function() {
var station = jQuery(this);
var name = station.find('name').text();
var latlng = new google.maps.LatLng(parseFloat(station.find('latitude').text()),
parseFloat(station.find('longitude').text()));
// get html for station-specific data
var content = station.find('description').text();
console.log(content); <--- empty string
setMarker(map, latlng, name, stressIcon, content)
});
});
将其作为 xml 检索,您应该能够正确调用文本:
jQuery.get("CRWGE_current_products.kml", {}, function(data) { }, 'xml');
我已经使用 USGS.gov 的 xml 提要完成了此操作,但尚未尝试使用 .kml。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)