2013-06-26 17 views
2

我試圖從地址使用Wakanda Studio中的Google地圖api v3獲取緯度座標。我也提交給了Wakanda論壇。我搜索了v3文檔,它基本上建議將JSON對象和回調函數傳遞給地理編碼,該代碼顯示在下面的代碼中。地理編碼服務返回未捕獲類型錯誤:#<Object>對象沒有方法「應用」

地理編碼調用也封裝在codeAddress函數中。當我運行代碼時,我可以看到包含lat長座標的Geocoder JSON對象結果。但是,我得到一個奇怪的錯誤消息:

Uncaught Error Type: Object #<Object> has no method 'apply' 

任何指針將不勝感激,讓我知道,如果你需要看到的截圖/的任何細節別的電子郵件,因爲我不能張貼在堆棧溢出截圖呢。

button1.click = function button1_click (event) 
{ 
    $$('map').setCenter("London, England");  
    var address1 = "911 South Park Street, Kalamazoo, MI, 49001"; 

    geocoder = new google.maps.Geocoder(); 

    if(!geocoder) { 
     alert("no geocoder available"); 
    } else { 
     alert("geocoder available"); 
    } 

    codeAddress(address1); 
}; 

function codeAddress(address) { 

    var address1 = address; 
    geocoder.geocode(
     {'address': address1}, 
     {onSuccess: function(results, status) { 

      if (status == google.maps.GeocoderStatus.OK) { 
       //setCenter to mid 
       //addMarker 
       var lat = results[0].geometry.location.lat; 
       var lon = results[0].geometry.location.lon; 
       alert(lat); 
      } else { 
       alert("geocoder issue " + status); 
      } 
     } 
    }); 

} 

回答

2

我也試過在Wakanda類似的東西,但它似乎在瀏覽器阻塞調用由於CORS(域的交叉引用),所以我用下面的方法。

Wakanda客戶端 - > Wakanda服務器 - >谷歌地圖API - >回到Wakanda服務器 - >返回Wakanda客戶

客戶端代碼:

button1.click = function button1_click (event) { 
    var address = $$("addressField").getValue(); 
    address = encodeURI(address); 
    // Make call to server 
    response = $sources.businesses.getGeoCoordinates(address); 
    address_info = JSON.parse(response); 

    if (address_info && address_info.status === "OK") { 
     $$("business_latitude_field").setValue(
      address_info.results[0].geometry.location.lat 
     ); 
     $$("business_longitude_field").setValue(
      address_info.results[0].geometry.location.lng 
     ); 
     alert('We got latitude & longitude of your address.'); 
    } else { 
     alert("Could not find latitude and longitude of your given address."); 
    } 
} 

服務器端代碼 - getGeoCoordinates公共方法的代碼中的業務數據類

function (address) { 
    // Call google geocode service to convert given address into lat/long 
    if (address) { 
     var api_url = "http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=" + address; 
     xhr = new XMLHttpRequest(); 
     xhr.open("GET", api_url); 
     xhr.send(); 
     var response = xhr.responseText; 
     return response; 
    } 
} 

何它有助於。

+0

當然,「企業」數據源必須創建客戶端 –

相關問題