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

1

6

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

Lousy answered 13/2, 2018 at 7:22 Comment(2)
Markers: developers.google.com/maps/documentation/static-maps/…Fatty
I wish! Static maps force static maps. That means you cannot launch Google Maps app, you cannot work with dynamic maps... Markers are nice but you do want to aim the map to a point, and let the user do whatever they do with it, when the "destination" is marked. By static maps you just display an image of the map :(Lousy
D
3

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!

Dissident answered 15/2, 2018 at 12:4 Comment(1)
Yeah, it is what it is :) As I suspected, I will need to do that in 2 calls. No shorter way.Lousy

© 2022 - 2024 — McMap. All rights reserved.