简体   繁体   中英

Google maps Places API nearby search for auto-check in

We are using the nearby search feature as described here ( https://developers.google.com/places/web-service/search ) to perform auto check-in in Android as well as iOS mobile apps.

However, when we call the web API, many of the nearby locations do not show up in our results. At the same time, I do receive notifications from the Google Maps App on my Android phone, asking if i am at the venue meaning the google maps app correctly detects my location.

As an example I was dining at Nando's located at: 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

But when I called the nearby search, Nando's did not show up in my list of nearby places. I checked and my gps coordinates were correct and google maps was able to detect my location and check me in.

Anybody know why this happens? Is there a workaround or a solution for this problem?

You didn't post the Places API query, so it is difficult to say what is wrong in your application.

I tried it myself and it worked for me as expected. Let suppose I have a GPS coordinate 41.885565,-87.62425, this is a position more or less of the Nando's you mentioned in the description (have a look at Geocoder tool):

https://google-developers.appspot.com/maps/documentation/utils/geocoder/#q%3D41.885565%252C-87.62425

Now I can create a nearby search request for location 41.885565,-87.62425 with results rank by distance, so the nearest place will be the first in response and also we have to apply a type parameter in the request according to the documentation :

If rankby=distance (described under Optional parameters below) is specified, then one or more of keyword, name, or type is required.

The resulting request is

https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=41.885565%2C-87.62425&rankby=distance&type=restaurant&key=MY_API_KEY

With this request I get Nando's (place ID ChIJ9xIeWq8sDogR9kpPM8dUTXE) as the first item in the response

"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"
},

I hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM