Google 附近的地图地点 API 搜索自动入住
Google maps Places API nearby search for auto-check in
我们正在使用此处描述的附近搜索功能 (https://developers.google.com/places/web-service/search) 在 Android 和 iOS 移动应用程序中执行自动登记。
但是,当我们调用网络 API 时,许多附近的位置不会显示在我们的结果中。同时,我在 Android phone 上确实收到来自 Google 地图应用程序的通知,询问我是否在会场意味着 google 地图应用程序正确检测到我的位置。
举个例子,我在 Nando's 用餐,地址是:
https://www.google.com/maps/place/Nando's+PERi-PERi/@41.8854864,-87.6238967,19.85z/data=!4m5!3m4!1s0x0:0x714d54c7334f4af6!8m2!3d41.885548!4d-87.624252
但是当我调用附近搜索时,Nando's 并没有出现在我的附近地点列表中。我检查了一下,我的 gps 坐标是正确的,google 地图能够检测到我的位置并检查我。
有人知道为什么会这样吗?此问题是否有解决方法或解决方案?
您没有post Places API 查询,因此很难说您的应用程序出了什么问题。
我自己试了一下,效果如我所料。假设我有一个 GPS 坐标 41.885565,-87.62425,这或多或少是你在描述中提到的 Nando 的位置(看看 Geocoder 工具):
https://google-developers.appspot.com/maps/documentation/utils/geocoder/#q%3D41.885565%252C-87.62425
现在我可以为位置 41.885565,-87.62425 创建一个附近的搜索请求,结果按距离排序,所以最近的地方将是第一个响应,而且我们必须根据documentation:
If rankby=distance (described under Optional parameters below) is specified, then one or more of keyword, name, or type is required.
结果请求是
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=41.885565%2C-87.62425&rankby=distance&type=restaurant&key=MY_API_KEY
通过此请求,我将 Nando 的(地点 ID ChIJ9xIeWq8sDogR9kpPM8dUTXE)作为响应中的第一项
"results":[
{
"geometry":{
"location":{
"lat":41.8855475,"lng":-87.6242518
},
"viewport":{
"northeast":{
"lat":41.8870082302915,"lng":-87.62290226970849
},
"southwest":{
"lat":41.8843102697085,"lng":-87.6256002302915
}
}
},
"icon":"https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
"id":"a29ff7d92a100fd6f5a8c0e34dff84806838f2d9",
"name":"Nando's PERi-PERi",
"opening_hours":{
"open_now":false,
"weekday_text":[
]
},
"photos":[
{
"height":3036,
"html_attributions":[
"Marco Laure"
],
"photo_reference":"CmRaAAAAwbEPFsgrrjKVrplwBAAmKhKe5CkFX9wn_x1ZF9d6K8rRdT8tRUiW23-qEGLwbuf1wePdUkSrSN21a8r696kXGv6KYG42mI7RaDf2n80iLJlDVtEXys1KK4Hn9_nebsLwEhC6CQemKH3oHLe52i5m-JzOGhQoYbUFTntC5IuEzvASfjPvhDgr_g",
"width":4048
}
],
"place_id":"ChIJ9xIeWq8sDogR9kpPM8dUTXE",
"price_level":1,
"rating":4.2,
"reference":"CmRRAAAARrKCjwMLRvvXncBVw9pCf8RNq1GpfjDrHD8Jh_du12zBJxJ_eaGidizxAny31qn24BgZDpab346A3_QYbgaUMMZOnratR9XBNkQNS1a-DCPSFggzNjsUoOl_QQkhQU-DEhDExmV2z_pyXAkAoxRzIAVQGhT5kjoH3myVM7-vraAlw0EG512ykw",
"scope":"GOOGLE",
"types":[
"restaurant","food","point_of_interest","establishment"
],
"vicinity":"117 East Lake Street, Chicago"
},
希望对您有所帮助!
我们正在使用此处描述的附近搜索功能 (https://developers.google.com/places/web-service/search) 在 Android 和 iOS 移动应用程序中执行自动登记。
但是,当我们调用网络 API 时,许多附近的位置不会显示在我们的结果中。同时,我在 Android phone 上确实收到来自 Google 地图应用程序的通知,询问我是否在会场意味着 google 地图应用程序正确检测到我的位置。
举个例子,我在 Nando's 用餐,地址是: https://www.google.com/maps/place/Nando's+PERi-PERi/@41.8854864,-87.6238967,19.85z/data=!4m5!3m4!1s0x0:0x714d54c7334f4af6!8m2!3d41.885548!4d-87.624252
但是当我调用附近搜索时,Nando's 并没有出现在我的附近地点列表中。我检查了一下,我的 gps 坐标是正确的,google 地图能够检测到我的位置并检查我。
有人知道为什么会这样吗?此问题是否有解决方法或解决方案?
您没有post Places API 查询,因此很难说您的应用程序出了什么问题。
我自己试了一下,效果如我所料。假设我有一个 GPS 坐标 41.885565,-87.62425,这或多或少是你在描述中提到的 Nando 的位置(看看 Geocoder 工具):
https://google-developers.appspot.com/maps/documentation/utils/geocoder/#q%3D41.885565%252C-87.62425
现在我可以为位置 41.885565,-87.62425 创建一个附近的搜索请求,结果按距离排序,所以最近的地方将是第一个响应,而且我们必须根据documentation:
If rankby=distance (described under Optional parameters below) is specified, then one or more of keyword, name, or type is required.
结果请求是
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=41.885565%2C-87.62425&rankby=distance&type=restaurant&key=MY_API_KEY
通过此请求,我将 Nando 的(地点 ID ChIJ9xIeWq8sDogR9kpPM8dUTXE)作为响应中的第一项
"results":[
{
"geometry":{
"location":{
"lat":41.8855475,"lng":-87.6242518
},
"viewport":{
"northeast":{
"lat":41.8870082302915,"lng":-87.62290226970849
},
"southwest":{
"lat":41.8843102697085,"lng":-87.6256002302915
}
}
},
"icon":"https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
"id":"a29ff7d92a100fd6f5a8c0e34dff84806838f2d9",
"name":"Nando's PERi-PERi",
"opening_hours":{
"open_now":false,
"weekday_text":[
]
},
"photos":[
{
"height":3036,
"html_attributions":[
"Marco Laure"
],
"photo_reference":"CmRaAAAAwbEPFsgrrjKVrplwBAAmKhKe5CkFX9wn_x1ZF9d6K8rRdT8tRUiW23-qEGLwbuf1wePdUkSrSN21a8r696kXGv6KYG42mI7RaDf2n80iLJlDVtEXys1KK4Hn9_nebsLwEhC6CQemKH3oHLe52i5m-JzOGhQoYbUFTntC5IuEzvASfjPvhDgr_g",
"width":4048
}
],
"place_id":"ChIJ9xIeWq8sDogR9kpPM8dUTXE",
"price_level":1,
"rating":4.2,
"reference":"CmRRAAAARrKCjwMLRvvXncBVw9pCf8RNq1GpfjDrHD8Jh_du12zBJxJ_eaGidizxAny31qn24BgZDpab346A3_QYbgaUMMZOnratR9XBNkQNS1a-DCPSFggzNjsUoOl_QQkhQU-DEhDExmV2z_pyXAkAoxRzIAVQGhT5kjoH3myVM7-vraAlw0EG512ykw",
"scope":"GOOGLE",
"types":[
"restaurant","food","point_of_interest","establishment"
],
"vicinity":"117 East Lake Street, Chicago"
},
希望对您有所帮助!