【发布时间】:2013-04-11 06:07:59
【问题描述】:
我有一个这样的 JSON --
....
"location" : {
"lat" : 37.42140090,
"lng" : -122.08537010
},
....
我正在尝试访问 lat 和 lng 值。我该怎么做?
我的代码
results[0].geometry.location.lat
or results[0].geometry.location.lng
不起作用。但是当我只使用 results[0].geometry.location 时,我得到了输出。
我使用的 JSON 是 -- http://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true
更新--
这就是我向 API 发出请求的方式
geocoder.geocode( { 'address': search_addr}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var t = results[0].geometry.location.lat;
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
谢谢
【问题讨论】:
-
什么是
geometrydatatype即json或array -
or实际上在您的代码中吗?其余部分看起来是正确的。 -
你有什么问题?出错了?
-
这是我写 alert(results[0].geometry.location.lat); 时得到的输出 ""function (){return this[a]}"";
-
请注意,
results是Object的属性。如果解析后的 JSON 存储在名为results的变量中,则查找可能需要从results.results[0].geometry...开始(对于每个变量和属性)。
标签: javascript json google-maps-api-3