androidgoogle-mapsreverse-geocodinggoogle-maps-urls

Google Maps: open URL by coordinates but show the location name


I've been trying to open Google Maps (specifically on Android, but not necessarily) from a coordinates URL, such as

https://www.google.com/maps/search/?api=1&query=51.5055,-0.0754

But when the map opens, I want it to show the location name such as "Tower Bridge". Not the coordinates 51.5055,-0.0754

I have tried something like

https://www.google.com/maps/search/?api=1&query=51.5055,-0.0754&query_place_id=Tower+Bridge

with no luck. When maps opens it shows the coordinates, not the place name.

I am okay with either "injecting" the location name (something like https://....&location_name=Traitors+Gate), and/or with maps revealing the location name (reverse geocoding) from the coordinates.

Motivation: Coordinates are more accurate and less ambiguous than location names. For example, there is Jerusalem, OH and there is Jerusalem, Israel, which is half a world away. Or, "Palais de Louvre" which is just one building but one huge building over four streets, with multiple entrances. Coordinates solve those issues, but they are not "Human readable". You can't present "49.3697,0.8711" to a user and expect them to recognise the Omaha Beach.

Thanks


Solution

  • Unfortunately, the Google Maps URLs doesn't support this kind of sending labels. You should send a valid place ID value in order to get correct title of the place in Google Maps app.

    You will need one additional step to do this. Execute reverse geocoding request for coordinate and get a place ID.

    https://maps.googleapis.com/maps/api/geocode/json?latlng=51.5055%2C-0.0754&language=en&key=YOUR_API_KEY

    This will return a place ID ChIJlRsEuUgDdkgRSM7ciIhVooM of Tower Bridge. Have a look at this example in Geocoder tool:

    https://google-developers.appspot.com/maps/documentation/utils/geocoder/#q%3D51.5055%252C-0.0754

    There is a Java client library for Google Maps API Web Services that you can find on GitHub:

    https://github.com/googlemaps/google-maps-services-java

    You can use this library to execute geocoding requests, alternatively you can also use Places API nearby search to get the nearest place. Note that web services require a different API key, because they don't support Android app restriction that you use in API key for Maps Android API.

    Once you get a place ID value just create Google Maps URLs link. E.g.

    https://www.google.com/maps/search/?api=1&query=51.5055,-0.0754&query_place_id=ChIJlRsEuUgDdkgRSM7ciIhVooM

    I hope this helps!