2

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 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を使用してdescriptionタグから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 に答える