Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Place Details Lat/Long coordinates not matching cross platform Maps URLs

I have used the Google Place details API to get the place details which includes the lat/lng coordinates of a place.

When I launch Google maps using the Universal cross-platform Maps URL, it does not recognize the Place.

For example,

https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJbf8C1yFxdDkR3n12P4DkKt0&key=XXXXXXXX

returns the place details including the following location data:

 {
  .....
  "geometry": {
    "location": {
      "lat": 27.1750151,
      "lng": 78.0421552
    },
    "viewport": {
      "northeast": {
        "lat": 27.1770292,
        "lng": 78.04537599999999
      },
      "southwest": {
        "lat": 27.16897280000001,
        "lng": 78.0388188
      }
    }
  },
  .....
  "name": "Taj Mahal",
  "place_id": "ChIJbf8C1yFxdDkR3n12P4DkKt0",

  .....
}

But this data, when used to create a Maps URL with direction map action, does not give the correct place in the destination field.

Google Maps URL : https://www.google.com/maps/dir/?api=1&destination=27.1750151,78.0421552&destination_place_id=ChIJbf8C1yFxdDkR3n12P4DkKt0

The destination is not shown as a place. Only the lat/lng or address is used as below.

Google Map URL with directions action

The correct/expected result is the following. Look at the destination.

The Expected result of opening the Maps URL

Update

The issue seems to be with the PlaceID not matching the lat/lng coordinates in the Maps URL. There seems to be an inconsistency with lat/lng provided by the Place Details API.

Below URL works

https://www.google.com/maps/dir/?api=1&destination=27.1750151,78.0421552,15z&destination_place_id=ChIJbf8C1yFxdDkR3n12P4DkKt0

but 27.1750151,78.0421552,15z is not the coordinates from the Place details API. The lat/lng returned by PlaceDetails API is 27.1750151,78.0421552.

There is a difference of ,15z which I believe it is the zoom levels.

like image 558
Sebin Benjamin Avatar asked Apr 01 '18 11:04

Sebin Benjamin


2 Answers

The destination parameter looks to be trumping the destination_place_id parameter completely when lat/lngs are supplied, causing a reverse geocode on the coordinates. In the following example URL, I'm using a Place ID of ChIJj61dQgK6j4AR4GeTYWZsKWw which corresponds to the Googleplex in Mountain View, CA as the destination_place_id along with the lat/lng for the Taj Mahal as the destination; notice the Googleplex query is ignored, and a reverse geocode is performed getting just the address in India:

https://www.google.com/maps/dir/?api=1&destination=27.1750151,78.0421552&destination_place_id=ChIJj61dQgK6j4AR4GeTYWZsKWw

enter image description here

So, the workaround is to not use a lat/lng as the destination parameter. I've tested with various strings (place names, addresses, gibberish) as that parameter, and the destination_place_id appears to supercede it, which is the desired behavior. When using just a .(period) as a universal value, the name of the place along with the address is supplied:

https://www.google.com/maps/dir/?api=1&destination=.&destination_place_id=ChIJj61dQgK6j4AR4GeTYWZsKWw

enter image description here

https://www.google.com/maps/dir/?api=1&destination=.&destination_place_id=ChIJbf8C1yFxdDkR3n12P4DkKt0

enter image description here

like image 129
Preston Avatar answered Sep 29 '22 06:09

Preston


The documentation mentions for destination that The value can be either a place name, address, or comma-separated latitude/longitude coordinates.

If you enter coordinates, I suppose it just does a reverse geocode and displays the corresponding address. So you can input the place name and it will work.

https://www.google.com/maps/dir/?api=1&destination=Taj+Mahal&destination_place_id=ChIJbf8C1yFxdDkR3n12P4DkKt0

like image 21
MrUpsidown Avatar answered Sep 29 '22 07:09

MrUpsidown