title: read a specific attribute in kml from javascript
body: <p>I have a map from mapquest API, and I'm also using Leaflet to display the zip codes, with a L.divIcon at the center of the polygon displaying the Zip code. Everything is working great except that I have to manually input the center of the polygon as a place to display the divIcon in javascript. </p>
  
  <p>What I would like to know is if there is a way to read the kml from javascript to get the center of the polygon. I can use Qgis to calculate the center and save it to a kml lie this:</p>
  
  <pre><code>    ........
      &lt;Placemark&gt;
  
      &lt;name&gt;77029&lt;/name&gt;
  
      &lt;ExtendedData&gt;&lt;SchemaData schemaUrl="#center_jacinto"&gt;
  
      &lt;SimpleData name="Descriptio"&gt;Jacinto City&lt;/SimpleData&gt;
      &lt;/SchemaData&gt;&lt;/ExtendedData&gt;
      //This is the data I want to read from javascript if I can-&gt;
      &lt;Point&gt;&lt;coordinates&gt;-95.262889587410186,29.761518060337306&lt;/coordinates&gt; 
      &lt;/Point&gt;
      .....
  </code></pre>
  
  <p>The kml will draw a marker which I don't want, I just want the lat and lon, which I will then draw my icon..</p>
  
  <p>edit:I added this but getting nothing, very new to javascript and html so I'm sure the order is wrong</p>
  
  <pre><code>     &lt;html&gt;
  
       &lt;head&gt;
       &lt;title&gt;Leaflet&lt;/title&gt;
       &lt;link rel="stylesheet" href="leaflet.css" /&gt;
       &lt;link rel="stylesheet" href="leaflet.label.css" /&gt;
  
  
       &lt;script src="leaflet.js"&gt;&lt;/script&gt;
      &lt;script src="leaflet.label.js"&gt;&lt;/script&gt;
  
      &lt;script src="KML.js"&gt;&lt;/script&gt;
      &lt;script src="http://www.mapquestapi.com/sdk/leaflet/v1.0/mq-map.js?key=key"&gt;
     &lt;/script&gt;
  
  
  
  
  
     &lt;/head&gt;
  
     &lt;/body &gt;
     &lt;div style="color:black ;width:100%; height:100%" id="map"&gt;&lt;/div&gt;
      &lt;script type='text/javascript'&gt;
  
  
  
  
     function myfunction()
     {
     alert('ok');
     if (window.XMLHttpRequest)
     {// code for IE7+, Firefox, Chrome, Opera, Safari
     xmlhttp=new XMLHttpRequest();
     }
     else
     {// code for IE6, IE5
     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
     }
  
     xmlhttp.open("GET","center_jacinto.kml",false);
     xmlhttp.send();
     xmlDoc=xmlhttp.responseXML;
     parser   = new DOMParser(); // new Parser
     xmlDoc = parser.parseFromString(xmlDoc,"text/xml"); // Parse string
     txt=xmlDoc.getElementsByTagName("Point")[0].childNodes[0].nodeValue;
     console.log(txt);
     }
  
  
  
     window.load = myfunction;
  
  
  
  
      var mapLayer = MQ.mapLayer();
  
  
      var map = new L.Map('map', {
      center: new L.LatLng(29.7630556,-95.3630556),
      zoom: 10
     });
     var layer = L.tileLayer('http://otile{s}.mqcdn.com/tiles/1.0.0/sat/{z}/{x}/{y}.jpeg', {
  
         attribution: 'xxxx',
         subdomains: '1234',
         }).addTo(map);
  
  
  
         var track = new L.KML("center_jacinto.kml", {async: true});
          track.on("loaded", function(e) { map.fitBounds(e.target.getBounds()); });
  
  
  
      map.addControl(new L.Control.Layers({'map': mapLayer.addTo(map)}, 
          {'jacinto':track
  
          }));
  
      console.log(map.getZoom());
      map.addLayer(track);
  
  
      map.addLayer(layer);
  
  
  
  
  
  
     &lt;/script&gt;
     &lt;/body&gt;
  
  
     &lt;/html&gt;
  </code></pre>