我正在检索一个 Google 地球 .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 coralreefwatch@noaa.gov 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)
});
});