位置字段缺少就地详细信息请求



我在使用google地图API时遇到问题。

这是我的请求:

https://maps.googleapis.com/maps/api/place/details/json?fields=name%2Crating%2Cformatted_phone_number%2Cformatted_address%2Cgeometry&place_id=place_id&密钥=API_key

我对我请求的所有字段都得到了正确的响应,但当我试图读取几何体内部的位置值时,我得到了这个错误:

TypeError:无法读取未定义的属性"location">

我如何尝试提取位置参数:

data["geometry"]["location"]

任何帮助都将不胜感激,谢谢!

{
"html_attributions" : [],
"result" : {
"formatted_address" : "Level 1, 2 and 3, Overseas Passenger Terminal, Circular Quay W, The Rocks NSW 2000, Australia",
"formatted_phone_number" : "(02) 9251 1188",
"geometry" : {
"location" : {
"lat" : -33.85873230000001,
"lng" : 151.2100055
},
"viewport" : {
"northeast" : {
"lat" : -33.8573990197085,
"lng" : 151.2112270302915
},
"southwest" : {
"lat" : -33.86009698029149,
"lng" : 151.2085290697085
}
}
},
"name" : "Cruise Bar",
"rating" : 4
},
"status" : "OK"
}
data["geometry"]["location"]

可能需要

data["result"]["geometry"]["location"]

假设CCD_ 1是JSON解析的主体。

最新更新