2012-11-06 84 views
1

我在使用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'); 
     } 
    } 

坚持一个alertconsole.log出来的handleApiReady第一行显示,它似乎并没有找到该功能。为什么会这样?

+1

handleApiReady确实是全局的(与window.handleApiReady相同)。 – geocodezip

+0

它工作正常。这是用户脚本的一部分吗?在这种情况下,可能是'@ grant'问题。 – RASG

回答

1

问题用我提供了被定位在document.ready代码引起的。将它移出document.ready解决了问题。