benpalmer
benpalmer

Reputation: 2088

GeoXML3 not returning any placemarks

I have a KML file containing some polygons that has been output from an application (not sure which one). When i try to load in the xml, it seems to load fine but doesn't return any placemarks, just an empty array.

Link to KML file

I have simplified the JS just for testing to the following:

var map = new google.maps.Map(document.getElementById('gmap'), {
  center: new google.maps.LatLng(51.503355, -0.127564),
  zoom: 12,
  mapTypeId: google.maps.MapTypeId.ROADMAP
});

var geoxml = new geoXML3.parser({ 
  map : map, 
  singleInfoWindow : false,
  afterParse: useTheData 
});
geoxml.parse('placemarks.kml');

function useTheData(doc) {
  console.log(doc[0].placemarks);
  for (var i = 0; i < doc[0].placemarks.length; i++) {
    console.log( doc[0].placemarks[i].name );
  }
};

When i log the placemarks object i just get [] in the console. Is the file wrong?

I have added the following to my .htaccess

AddType application/vnd.google-earth.kml+xml .kml

And replaced GeoXML.fetchXML with the following (as i was getting "Unable to retreive placemarks.kml")

geoXML3.fetchXML = function (url, callback) {
  function timeoutHandler() {
    callback();
  };
  $.ajax({
      type:       "GET",
      cache:      false,      
      url: url,
      success: function(xml) {
          callback(xml);
      }
  });
};

Upvotes: 1

Views: 1079

Answers (1)

geocodezip
geocodezip

Reputation: 161334

You need to use geoxml3 from the polys branch or the kmz branch. The trunk is old and doesn't support polygons.

working example with your KML using the polys branch

working example with your KML using the kmz branch

Upvotes: 2

Related Questions