Question

Je suis la récupération d'un fichier de Google Earth (xml) et en utilisant le contenu de placer des marqueurs dans Google Maps. Les balises XML particulier Je suis intéressé par ressembler à:

<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>

Le code suivant extrait le nom et lat et long, mais je ne sais pas comment extraire le CDATA de la balise de description à l'aide jQuery. Je voudrais être en mesure d'extraire le code html réel pour que je puisse l'utiliser dans un infowindow pour le marqueur Google Maps.

// 
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)
  });
});
Était-ce utile?

La solution

Récupérer au format XML et vous devriez être en mesure d'appeler correctement le texte:

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

Je l'ai fait avec des flux XML à partir USGS.gov, mais je ne l'ai pas essayé avec .kml.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top