您好我正在使用谷歌地方api javascript sdk,並希望將結果保存在我的數據庫中使用ROR - 我想知道,前四天,它正在節省lat/lng成功,但現在它保存爲空。下面是我的解釋谷歌地圖經緯度在幾何中顯示爲空 - Javascript
我有這個代碼在我的JavaScript
places = new google.maps.places.PlacesService(map);
places.nearbySearch(request, callback);
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
clearMarkers();
//alert(JSON.stringify(results));
$.ajax({
url: "/myurl",
data:{
'google_searched_locations': JSON.stringify(results)
},
dataType: "json",
method: 'post',
async : false,
success: function(data){
}
});
}
在回調函數當我這樣做console.log(results[0].geometry.location.lng());
它顯示我作爲結果而74.30889000000002
當我做
console.log(results[0]);
輸出
geometry
Object { location=L}
location
L { lat=function(), lng=function(), toString=function(), more...}
equals function(a)
j function(a)
lat function()
lng function()
toString function()
這顯然是有道理的。但在Firefox的控制檯,AJAX數據參數表示數據在下面的形式
[{"geometry":{"location":{}}]
我跳過爲了清楚起見,其它參數,因爲所有其他的事情存在於該請求。但是你可以看到位置完全是空的,爲什麼?以及如何發送results[0].geometry.location.lng()
值,即在位置對象內
親愛的你正確地解釋了邏輯,但@vadim也給出了邏輯代碼,這就是爲什麼我將這個標記爲答案,但是你的答案也是100%正確的 – ImranNaqvi