1

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?

adbo
  • 133
  • 1
  • 1
  • 10

2 Answers2

4

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.

adbo
  • 133
  • 1
  • 1
  • 10
3

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)

Community
  • 1
  • 1
geocodezip
  • 158,664
  • 13
  • 220
  • 245
  • Many thanks for the great response and demo. Could you elaborate on what you mean by 'The KML needs to be in the same domain as the page which is loading it...'? I thought I was doing that when I put the kml in the same folder as the geoxml3.js file? – adbo Feb 05 '14 at 18:15
  • 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: [working](http://www.geocodezip.com/geoxml3_test/v3_geoxml3_kmltest_linkto.html?filename=http://www.geocodezip.com/geoxml3_test/SO_test_20140205_fill1.kml), [not working](http://www.geocodezip.com/geoxml3_test/v3_geoxml3_kmltest_linkto.html?filename=http://geocodezip.com/geoxml3_test/SO_test_20140205_fill1.kml), `geocodezip.com` and `www.geocodezip.com` are different domains (no matter how similar they may look) – geocodezip Feb 05 '14 at 18:39
  • Ok sorry now I'm confused. Your initial response had linked to a map that had my kml loaded via geoxml3 and was responding to mouseovers. Now I only see an example that adds kml layers directly. I need the geoxml to access the polygons inside the kml. I don't think I could implement the proxy solution with this particular client. Could you please elaborate on how to have geoxml access the file if it local on the webserver? EDIT: sorry posted this w/o reloading and didn't see your response. thx – adbo Feb 05 '14 at 18:42
  • Define "local on the server". A relative URL will work as long as the file is at that location and the [server is configured to serve it](https://developers.google.com/kml/documentation/kml_tut#kml_server). – geocodezip Feb 05 '14 at 18:47
  • I have the kml file sitting in the same folder as the geoxml3.js file. I've added the 'AddType' statements to my httpd.conf but I'm still not getting any love. I've tried the following: myParser.parse('http://localhost/ottawa_drupal/sites/default/files/ontario_regions_yan_1.kml'); myParser.parse('./ontario_regions_yan_1.kml'); myParser.parse('ontario_regions_yan_1.kml'); sorry for the formatting – adbo Feb 05 '14 at 19:01
  • 1
    A relative path is relative to where the _page_ is being served from, not geoxml3.js. – geocodezip Feb 05 '14 at 19:09
  • can't make this a chat. Thanks for clearing that up. – adbo Feb 05 '14 at 19:19
  • I don't do chat either whatever SO wants. – geocodezip Feb 05 '14 at 19:23