2

我正在检索一个 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)
  });
});
4

1 回答 1

3

将其作为 xml 检索,您应该能够正确调用文本:

jQuery.get("CRWGE_current_products.kml", {}, function(data) { }, 'xml');

我已经使用来自 USGS.gov 的 xml 提要完成了这项工作,但我还没有尝试使用 .kml。

于 2010-02-22T05:08:59.233 回答