2011-07-19 24 views
8

Tôi đang hiển thị bản đồ google trong trang web của mình và nó hoạt động chính xác trong tất cả các trình duyệt ngoại trừ Safari.Kịch bản Google Maps phá vỡ Safari TypeError: Kết quả biểu thức 'document.body' [null] không phải là một đối tượng

Safri trắng ra trang và lỗi JS nói:

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 

Các mã này có vẻ là đến từ một kịch bản tôi đang liên kết đến từ google sử dụng dòng này:

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

Kịch bản trông giống như sau:

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/[email protected]\u0026src=api\u0026hl=en-US\u0026","http://mt1.googleapis.com/[email protected]\u0026src=api\u0026hl=en-US\u0026"],null,null,null,null,"[email protected]"],[["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/[email protected]\u0026src=api\u0026hl=en-US\u0026","http://mt1.googleapis.com/[email protected]\u0026src=api\u0026hl=en-US\u0026"],null,null,"imgtp=png32\u0026",null,"h[email protected]"],[["http://mt0.googleapis.com/[email protected],[email protected]\u0026src=api\u0026hl=en-US\u0026","http://mt1.googleapis.com/[email protected],[email protected]\u0026src=api\u0026hl=en-US\u0026"],null,null,null,null,"[email protected],[email protected]"],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"); 
})();  

Tôi tin rằng đây có thể là dòng gây ra sự cố:

document.body.appendChild(s); 

Bất kỳ ý tưởng nào?

+0

bạn đã bao giờ tìm thấy giải pháp chưa? Tôi đã có cùng một vấn đề – Fabdrol

+0

nope tôi không bao giờ tìm thấy một giải pháp. Tôi đã tìm thấy rất nhiều người phàn nàn về cùng một vấn đề trên bảng thông báo của apple và google và không nhận được câu trả lời nào. – LennonR

+0

Trong mã của tôi, nếu tôi không chỉ định tham số 'callback' thì tôi sẽ không gặp lỗi. Cách duy nhất tôi có thể lấy API GMaps để tải với tham số 'callback' là tải tập lệnh trong phần' body'. Tôi sẽ chỉnh sửa câu hỏi của bạn một chút để nó bật lên danh sách một chút. – robertc

Trả lời

0

Sự thay đổi này đã giải quyết một số vấn đề tải trong trường hợp của tôi trên safari và IE7:

  • Hãy thử thêm các phiên bản trong url kịch bản: &v=3.7 đó là phiên bản đóng băng. Tránh sử dụng phiên bản 3.exp gây ra một số vấn đề tải.
0

Tôi đã tìm thấy giải pháp cho giải pháp này. Hãy thử tải Google Maps API một cách không đồng bộ. làm việc cho tôi

Asynchronously Loading the API

+0

Chào mừng bạn đến với SO. Không đặt liên kết vào bài đăng dưới dạng câu trả lời. Đặt phần quan trọng từ liên kết đủ để trả lời câu hỏi và cung cấp liên kết để biết thêm chi tiết. Các liên kết cũng không phải lúc nào cũng hợp lệ. –

+0

Liên kết đến tài liệu chính thức của google về cách sử dụng bản đồ không đồng bộ API..anyways chắc chắn sẽ ghi nhớ điều này ... cảm ơn :) – user2989148

0

tôi phải đối mặt với cùng một vấn đề trong khi làm việc trên OS X 10.10 và Safari. Giải quyết nó bằng cách thêm async và trì hoãn thẻ script.

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

Heres những gì các tài liệu có nói:

Synchronously Loading the API

In the script tag that loads the Maps API, it is possible to omit the async attribute and the callback parameter. This will cause the loading of the API to block until the API is downloaded.

This will probably slow your page load. But it means you can write subsequent script tags assuming that the API is already loaded.

Ngoài ra, bạn chắc chắn nên chắc chắn rằng div có chiều cao dành cho nó. chiều cao mặc định của div là 0 nếu không được chỉ định, điều này sẽ ẩn bản đồ mặc dù nó tải.

chúc may mắn.

Các vấn đề liên quan