Home > Enterprise >  Extracting Coordinates from a link Google Map API
Extracting Coordinates from a link Google Map API

Time:07-06

Is there any way to retrieve latitude and longitude using this type of google map link?

https://goo.gl/maps/7jNqZtPa5Cjf333k7

In this URL 7jNqZtPa5Cjf333k7 is not referring to place id right? I'm really struggling to extract latitude and longitude using this type of link. Really appreciate your help if somebody can give me an idea. Or else retrieving the place id also can be a help for me so I can use the link like this to retrieve the response in a JSON format.

https://maps.googleapis.com/maps/api/geocode/json?place_id=7jNqZtPa5Cjf333k7&key=YOUR_API_KEY

CodePudding user response:

There is no way to decode it without following the redirection.

That link redirects to: https://www.google.com/maps/place/Kandanawatta, Sri Lanka/@6.8391224,80.0308563,17z/data=!3m1!4b1!4m5!3m4!1s0x3ae2523ff96d8abf:0x4a6d8d4b68830686!8m2!3d6.8391224!4d80.0308563?hl=en-US

To decode the information in that link, see related questions:

The latitude and longitude for the location in that link is:

8m2!3d6.8391224!4d80.0308563
6.8391224,80.0308563

For Kandanawatta, Sri Lanka, the Google Places API returns:

Kandanawatta, Sri Lanka (6.837274799999999, 80.0325338)

Which is not quite the same, hard to say why without knowing where you got the "shortened" URL from.

The coordinates at the beginning (following the @):

6.8391224,80.0308563,17z

Are the center and zoom level of the map, not necessarily the location in the original request

  • Related