dman
dman

Reputation: 11073

Google's Places API gives off results - what can I do to get more accurate results with lat and lng?

Using Google maps api, I am trying to get information at a coffee shop I am at (for example).

On google maps, it shows 30.28456,-97.71936

enter image description here

In the Place IDs api, I consume the api with https://maps.googleapis.com/maps/api/place/nearbysearch/json?key=****&location=30.28456,-97.71936&radius=20

The first issue is that I have to use at least a radius 20m, if I go any smaller it will not include the Thunderbird Coffee Shop. This means with a radius of 20m, I also get other locations that I am not looking for.

The second issue is, the location lat and lng are not the same in the returned output below for Thunderbird Coffee Shop. The returned snippet shows 30.284403, -97.7194011 while Google maps shows 30.28456,-97.71936.

Why are the results so off? Is there something I can do differently to get a more accurate reading of the place I am at with Googles geolocation apis? I am using lat and lng because I get that from the browser in my web app.

        {
          "business_status": "OPERATIONAL",
          "geometry": {
            "location": {
              "lat": 30.284403,
              "lng": -97.7194011
            },
            "viewport": {
              "northeast": {
                "lat": 30.2856802802915,
                "lng": -97.71801381970849
              },
              "southwest": {
                "lat": 30.2829823197085,
                "lng": -97.7207117802915
              }
            }
          },
          "icon": "https://maps.gstatic.com/mapfiles/place_api/icons/v1/png_71/restaurant-71.png",  
          "icon_background_color": "#FF9E67",
          "icon_mask_base_uri": "https://maps.gstatic.com/mapfiles/place_api/icons/v2/restaurant_pinlet",
          "name": "Thunderbird Coffee",
          "opening_hours": {
            "open_now": true
          },
          "photos": [
            { 
              "height": 1536,
              "html_attributions": [
                "<a href=\"https://maps.google.com/maps/contrib/100343333546892327834\">Roy Gutierrez</a>"
              ],
              "photo_reference": "AcYSjRgYToIRiy6i83ZoEP-9-ps2rTFEWoryr52r03LzaHYQ-nJiRm6ho24ut_LNNdKDx551awteSNyfXP_HmbMFvJtzuRirXhCAE4lX1X1CjfGhuNtNoTvxaF6mFyxCHGWQwiuOEIutxahOqWMaoSSCMRra6I4z8_jrMEtkdatQuX6Kq1ml",
              "width": 2048
            }
          ],
          "place_id": "ChIJ2VQltuy1RIYRKhsPk6k9JaA",
          "plus_code": {
            "compound_code": "77MJ+Q6 Austin, TX, USA",
            "global_code": "862477MJ+Q6"
          },
          "price_level": 1,
          "rating": 4.5,
          "reference": "ChIJ2VQltuy1RIYRKhsPk6k9JaA",
          "scope": "GOOGLE",
          "types": [
            "restaurant",
            "cafe",
            "store",
            "food",
            "point_of_interest",
            "establishment"
          ],
          "user_ratings_total": 676,
          "vicinity": "2200 Manor Road, Austin"
        },

Upvotes: 1

Views: 661

Answers (1)

Yrll
Yrll

Reputation: 2581

I'm assuming that in your first issue, you just wanted to know how to search for the place details with greater than 20 search radius and still return the result you want. And the second one is that you want to know how is the API result different from the Tactile Map.

For your issue #1, I will include it in my explanation later but your issue #2 seems to be just an error on your part. The coordinates 30.28456, -97.71936 is not what the Google Maps showed as a location of the "Thunder Bird Coffee". I don't know how you got this value, but this is the coordinates from the building beside it. The actual coordinates of the Marker that points to the coffee shop is actually 30.284382,-97.719384.

Coordinates comparison1

To investigate further, I tried to use the Nearby Search of Places API.

I used these parameters: location=30.28456,-97.71936(I even used the wrong one you gave), radius=100(referring to your issue #1), and type=cafe(to avoid issue #1 of including places you don't want on your result).

Here's the actual request if you wanna check it out yourself(Use your own API Key): https://maps.googleapis.com/maps/api/place/nearbysearch/json?&location=30.28456,-97.71936&radius=100&type=cafe&key=API_KEY

Then here's the result I got:

enter image description here

The resulting coordinates of Google Maps and Nearby Search was within the premise of the right building.

"Note: Google Maps and Google Maps Platform are different products, so you should set your expectation that not all results would perfectly be the same but they would be pretty close"

Coordinates comparison2

Now, both of these have the same Place ID for the Thunderbird coffee shop and I believe this is working as intended and is accurate as it can get to help you in using Geolocation API.

Hope this helps. Please feel free to comment if you need any more help.

Upvotes: 2

Related Questions