Google Maps script breaks Safari TypeError: Result of expression document.body [null] is not an object

I display google maps on my web page and it works correctly in all browsers except Safari.

Safri turns off the page and the JS error says:

TypeError: Result of expression 'document.body' [null] is not an object. maps.google.com/maps/api/js?sensor=true&region=nz&async=2&callback=initializeConfigMap:11 TypeError: Result of expression 'a' [null] is not an object. maps.gstatic.com/intl/en_us/mapfiles/api-3/5/11/main.js:30 

The code, which apparently comes from the script, I contact google with this line:

 $.getScript("http://maps.google.com/maps/api/js?sensor=true&region=nz&async=2&callback=initializeConfigMap", function () {}); 

The script looks like this:

 window.google = window.google || {}; google.maps = google.maps || {}; (function() { function getScript(src) { var s = document.createElement('script'); s.src = src; document.body.appendChild(s); } var modules = google.maps.modules = {}; google.maps.__gjsload__ = function(name, text) { modules[name] = text; }; google.maps.Load = function(apiLoad) { delete google.maps.Load; apiLoad([null,[[["http://mt0.googleapis.com/vt?lyrs=m@158\u0026src=api\u0026hl=en-US\u0026","http://mt1.googleapis.com/vt?lyrs=m@158\u0026src=api\u0026hl=en-US\u0026"],null,null,null,null,"m@158"],[["http://khm0.googleapis.com/kh?v=88\u0026hl=en-US\u0026","http://khm1.googleapis.com/kh?v=88\u0026hl=en-US\u0026"],null,null,null,1,"88"],[["http://mt0.googleapis.com/vt?lyrs=h@158\u0026src=api\u0026hl=en-US\u0026","http://mt1.googleapis.com/vt?lyrs=h@158\u0026src=api\u0026hl=en-US\u0026"],null,null,"imgtp=png32\u0026",null,"h@158"],[["http://mt0.googleapis.com/vt?lyrs=t@127,r@158\u0026src=api\u0026hl=en-US\u0026","http://mt1.googleapis.com/vt?lyrs=t@127,r@158\u0026src=api\u0026hl=en-US\u0026"],null,null,null,null,"t@127,r@158"],null,[[null,0,7,7,[[[330000000,1246050000],[386200000,1293600000]],[[366500000,1297000000],[386200000,1320034790]]],["http://mt0.gmaptiles.co.kr/mt?v=kr1.14\u0026hl=en-US\u0026","http://mt1.gmaptiles.co.kr/mt?v=kr1.14\u0026hl=en-US\u0026"]],[null,0,8,9,[[[330000000,1246050000],[386200000,1279600000]],[[345000000,1279600000],[386200000,1286700000]],[[348900000,1286700000],[386200000,1293600000]],[[354690000,1293600000],[386200000,1320034790]]],["http://mt0.gmaptiles.co.kr/mt?v=kr1.14\u0026hl=en-US\u0026","http://mt1.gmaptiles.co.kr/mt?v=kr1.14\u0026hl=en-US\u0026"]],[null,0,10,19,[[[329890840,1246055600],[386930130,1284960940]],[[344646740,1284960940],[386930130,1288476560]],[[350277470,1288476560],[386930130,1310531620]],[[370277730,1310531620],[386930130,1320034790]]],["http://mt0.gmaptiles.co.kr/mt?v=kr1.14\u0026hl=en-US\u0026","http://mt1.gmaptiles.co.kr/mt?v=kr1.14\u0026hl=en-US\u0026"]],[null,3,7,7,[[[330000000,1246050000],[386200000,1293600000]],[[366500000,1297000000],[386200000,1320034790]]],["http://mt0.gmaptiles.co.kr/mt?v=kr1p.12\u0026hl=en-US\u0026","http://mt1.gmaptiles.co.kr/mt?v=kr1p.12\u0026hl=en-US\u0026"]],[null,3,8,9,[[[330000000,1246050000],[386200000,1279600000]],[[345000000,1279600000],[386200000,1286700000]],[[348900000,1286700000],[386200000,1293600000]],[[354690000,1293600000],[386200000,1320034790]]],["http://mt0.gmaptiles.co.kr/mt?v=kr1p.12\u0026hl=en-US\u0026","http://mt1.gmaptiles.co.kr/mt?v=kr1p.12\u0026hl=en-US\u0026"]],[null,3,10,null,[[[329890840,1246055600],[386930130,1284960940]],[[344646740,1284960940],[386930130,1288476560]],[[350277470,1288476560],[386930130,1310531620]],[[370277730,1310531620],[386930130,1320034790]]],["http://mt0.gmaptiles.co.kr/mt?v=kr1p.12\u0026hl=en-US\u0026","http://mt1.gmaptiles.co.kr/mt?v=kr1p.12\u0026hl=en-US\u0026"]]],[["http://cbk0.googleapis.com/cbk?","http://cbk1.googleapis.com/cbk?"]],[["http://khmdb0.googleapis.com/kh?v=40\u0026hl=en-US\u0026","http://khmdb1.googleapis.com/kh?v=40\u0026hl=en-US\u0026"],null,null,null,null,"40"],[["http://mt0.googleapis.com/mapslt?hl=en-US\u0026","http://mt1.googleapis.com/mapslt?hl=en-US\u0026"]],[["http://mt0.googleapis.com/mapslt/ft?hl=en-US\u0026","http://mt1.googleapis.com/mapslt/ft?hl=en-US\u0026"]],[["http://mt0.googleapis.com/vt?hl=en-US\u0026","http://mt1.googleapis.com/vt?hl=en-US\u0026"]]],["en-US","NZ",null,0,null,"http://maps.google.com","http://maps.gstatic.com/intl/en_us/mapfiles/","http://csi.gstatic.com","https://maps.googleapis.com","http://maps.googleapis.com"],["http://maps.gstatic.com/intl/en_us/mapfiles/api-3/5/11","3.5.11"],[3021543403],1.0,null,null,null,null,1,"initializeConfigMap",null,null,0,"http://khm.googleapis.com/mz?v=88\u0026"], loadScriptTime); }; var loadScriptTime = (new Date).getTime(); getScript("http://maps.gstatic.com/intl/en_us/mapfiles/api-3/5/11/main.js"); })(); 

I believe this may be the problem causing the problems:

 document.body.appendChild(s); 

Any ideas?

+8
javascript google-maps google-maps-api-3
source share
3 answers

This change solved some boot problems in my case on safari and ie7:

  • Try adding the version to the script url: &v=3.7 , which is the frozen version. Avoid using version 3.exp, which causes some loading problems.
0
source share

I found a solution for this. Try loading the Google Maps API asynchronously. worked for me

API Asynchronous Download

0
source share

i encountered the same problem when working with OS X 10.10 and Safari. Solved it by adding async and postponing the script tag.

 <script async defer src="https://maps.googleapis.com/maps/api/js?key=...."/> 

Here is what the documentation has to say:

API Synchronous Download

In the script tag that loads the Maps API, you can omit the asynchronous attribute and callback parameter. This will result in loading the API to lock before loading the API.

This will probably slow down the loading of your page. But that means you can write subsequent script tags that assume the API is already loaded.

In addition, you must make sure that the div has a given height. the default height of the div is 0, if not specified, this will hide the map, even if it is loading.

good luck.

0
source share

All Articles