[英]Read data from json response through ajax call
我正在執行ajax
調用以從pin碼獲取經度和緯度。
$(document).ready(function () {
$.ajax({
type: "GET",
url: "http://maps.googleapis.com/maps/api/geocode/json?address=753010,India&sensor=false",
data: {},
dataType:"json",
success: function (results) {
console.log(results);
console.log(results.length);
//alert(results.geometry.location.lat);
//alert(results.geometry.location.lng);
},
error: function (ex) {
alert("Error");
}
});
});
我得到的響應如下圖
但是我無法使用此results.geometry.location.lat
來獲取經度和緯度,我也嘗試過results[0]
。
請幫助查找經度和緯度。 另外,如果我沒有記錯的話,還可以提供適當的經度和緯度。
根據文檔 :
當地址解析器返回結果時,會將其放置在(JSON)結果數組中 。 即使地址解析器未返回任何結果(例如,地址不存在),它仍然會返回一個空的結果數組 。
請注意,返回的JSON可能包含多個值,如果要捕獲所有可能的值,最好遍歷結果數組的長度。 實際上,您可能只希望訪問第一個結果results[0]
位置。
results.results[0].geometry.location.lat
和results.results[0].geometry.location.lng
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.