Mike N
Mike N

Reputation: 103

Can't load google map Geojson data in IE 9

I'm getting the below error when trying to load GeoJson data in a map in IE9 using Javascript

Object doesn't support this property or method

My method call looks like below

myMap.data.loadGeoJson('https://storage.googleapis.com/maps-devrel/google.json');

I believe it has something to do with the .data call, as the only lines it happens on are ones that include .data in them. The "myMap" variable is initialized and set to a google map, and that all works fine, it's just when I try to load the geojson that it breaks.

Does anyone know why it would be breaking in IE9?

I've also attached a shot from Browserstack on similar errors using the google demo page...

IE9 Geojson Bug

UPDATE: I've talked to a google developer directly and it seems like a bug currently with IE9 (and I believe 8 as well), loading geojson does not work. If anyone does find a workaround though, it would be greatly appreciated. Even just knowing exactly why it's breaking would be good...

Upvotes: 0

Views: 387

Answers (2)

Florian
Florian

Reputation: 19

I had the same problem with IE.

Try this:

Open IE, Open "Tools", click on "Compatibility View Settings" and then uncheck "disable intranet sites in Compatibility View Setting" and then try to open your page.

That worked for me.

Upvotes: 1

Stephen Farrar
Stephen Farrar

Reputation: 71

The sample code loads the GeoJSON from a different server (cross-domain).

The problem is that .loadGeoJson() is using XMLHttpRequest to load the data, and on IE8 and IE9 this doesn't work cross-domain.

This is the "Access is denied" error you can see in the console.

Try putting the GeoJSON on the same server.

Or, if you really need to load GeoJSON cross-domain and support IE9, use an ajax library, and the .addGeoJson() method. It would look something like this using jQuery:

$.ajax({
    url: myURL,
    dataType: 'json',
    success: function(geojson) {
        myMap.data.addGeoJson(geojson);
    }
    // Other options to configure for jsonp, etc.
});

Upvotes: 0

Related Questions