我在使用Google Maps API時遇到問題。由於window.handleApiReady導致Google Maps API無法加載功能錯誤
單頁加載得到錯誤window.handleApiReady is not a function
,它當然是。望着下面你的代碼可以看到我使用它作爲一個回調函數:
/**
* Load GoogleMaps API
*/
$(function(){
script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'http://maps.google.com/maps/api/js?sensor=false&callback=handleApiReady';
document.body.appendChild(script);
});
/**
* Show map once GoogleMaps API is ready
*/
function handleApiReady() {
if ($("#map_canvas").length > 0) {
var latlng = $("#store_lat_long").html();
var details = latlng.split(',');
initialize(Number(details[0]), Number(details[1]), 'map_canvas');
}
}
堅持一個alert
或console.log
出來的handleApiReady
第一行顯示,它似乎並沒有找到該功能。爲什麼會這樣?
handleApiReady確實是全局的(與window.handleApiReady相同)。 – geocodezip
它工作正常。這是用戶腳本的一部分嗎?在這種情況下,可能是'@ grant'問題。 – RASG