It turns out that unfortunately I didn't have the correct version of geoxml3.js. I downloaded the file from the polys branch and everything works perfectly.
GeoXML3 unable to retrieve KML file
-
07-10-2022 - |
Pregunta
For some reason I can not get geoxml3 to load my KML file. I've tried using a publicly available URL for the file, and a local reference to the file in Chrome, Safari and Firefox all with no effect. When I use Chrome, I get a console message that says
Unable to retrieve file.
My code is very simple:
function initialize() {
var infowindow = new google.maps.InfoWindow({size: new google.maps.Size(150,50) });
var map_canvas = document.getElementById('map_canvas');
var center = new google.maps.LatLng(53, -88);
var map_options = {
center: center,
zoom: 4,
mapTypeId: google.maps.MapTypeId.TERRAIN
};
var map = new google.maps.Map(map_canvas, map_options);
var myParser = new geoXML3.parser({map: map, singleInfoWindow: true});
myParser.parse('https://sites.google.com/site/.../home/kml-files/ontario_regions_yan_1.kml');
}
I've tried all the various solutions offered in other questions but have been unable to get the file to load! Is there something simple I'm missing?
Solución
Otros consejos
geoxml3 uses xmlHttpRequest to retrieve the KML, xmlHttpRequest has a same domain restriction. The KML needs to be in the same domain as the page which is loading it or be loaded through a proxy which is in the same domain as the page which is loading it.
SO question - xmlHttpRequest and cross-site restriction
your KML on geocodezip.com through a proxy
KmlLayer doesn't have that restriction (google server is loading the KML directly)
The domain needs to be the same. Relative URLs ensure that. Trying to load something from http://geocodezip.com
on a page on http://www.geocodezip.com
won't work:
geocodezip.com
and www.geocodezip.com
are different domains (no matter how similar they may look). A relative path is relative to where the page is being served from (not the geoxml3.js script)