使用 Place AutoComplete WebService API 获取纬度和经度
Using Place AutoComplete WebService API to get the Lat and Long
实施了 Places Web Service API
- 地点自动完成 https://developers.google.com/places/web-service/autocomplete 并且工作正常,但它没有 return 预测这些地点的纬度和经度!
这就是要求!
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Amoeba&types=geocode&location=37.76999,-122.44696&radius=500®ions=locality&key=KEY
这是预期的行为。根据文档,自动完成响应不包含任何位置信息:
https://developers.google.com/places/web-service/autocomplete#place_autocomplete_results
您在响应中有地点 ID,因此您可以执行地点详细信息或地理编码请求以获取给定地点的位置。
比如你的请求中第一个预测有一个地点ID ChIJjxz0JSktaE0RJio-PNWLd60,那么你可以执行如下请求获取坐标:
https://maps.googleapis.com/maps/api/geocode/json?place_id=ChIJjxz0JSktaE0RJio-PNWLd60&key=YOUR_API_KEY
响应将包含所需信息
"geometry":{
"bounds":{
"northeast":{
"lat":50.0903542,"lng":-86.29135079999999
},
"southwest":{
"lat":50.0850891,"lng":-86.3070178
}
},
"location":{
"lat":50.0890102,"lng":-86.2987103
},
....
我还可以看到功能请求已在 Google 问题跟踪器中提交,但 Google 拒绝并标记为不可行:
实施了 Places Web Service API
- 地点自动完成 https://developers.google.com/places/web-service/autocomplete 并且工作正常,但它没有 return 预测这些地点的纬度和经度!
这就是要求!
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Amoeba&types=geocode&location=37.76999,-122.44696&radius=500®ions=locality&key=KEY
这是预期的行为。根据文档,自动完成响应不包含任何位置信息:
https://developers.google.com/places/web-service/autocomplete#place_autocomplete_results
您在响应中有地点 ID,因此您可以执行地点详细信息或地理编码请求以获取给定地点的位置。
比如你的请求中第一个预测有一个地点ID ChIJjxz0JSktaE0RJio-PNWLd60,那么你可以执行如下请求获取坐标:
https://maps.googleapis.com/maps/api/geocode/json?place_id=ChIJjxz0JSktaE0RJio-PNWLd60&key=YOUR_API_KEY
响应将包含所需信息
"geometry":{
"bounds":{
"northeast":{
"lat":50.0903542,"lng":-86.29135079999999
},
"southwest":{
"lat":50.0850891,"lng":-86.3070178
}
},
"location":{
"lat":50.0890102,"lng":-86.2987103
},
....
我还可以看到功能请求已在 Google 问题跟踪器中提交,但 Google 拒绝并标记为不可行: