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.
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);
}
});
};
You need to use geoxml3 from the polys branch or the kmz branch. The trunk is old and doesn't support polygons.