I need a way to figure out the latitude, longitude of a place in google map provided its link. Alternatively, it is fine if I can plot the point inside my application on a map, if possible, or share the latitude longitude from google map using some intent, so that I can receive it from within my application. Is any of the above possible directly or indirectly?
In short, I have a google map URL with me(which I may have received in WhatsApp or similar platform), and using that, somehow, I need to get the latitude and longitude of the place within my application, even if it is an indirect way. I am not interested in places API, since it having a limit.
Have been trying to get to a solution for a few hours, didn't find anything relevant.
EDIT:
Samples of link I am trying to use:
(Not able to use URL shortners, since SO doesn't allow, replace [dot] with .)
Seems, there is no one common solution for all types of encoded URLs, but for described two you can use:
1) for URLs like
https://goo[dot]gl/maps/fSQSTjDR32m- Google URL Shortener API with requests like:NB! You need valid key for your Android app with enabled URL Shortener API on Developer Console
You can use
HttpURLConnectionto get responseor use URL Shortener API Client Library for Java. For more details take a look at this question of Ogre and answers.
So, for your shortened URL you should get JSON response like:
where
longUrltag contains URL with desired latitude-longitude. According to this answer of treebles:And you can find latitude-longitude in
longUrlby!3dand!4dprefixes or using regular expression.2) for URLs like https://maps.google.com/?cid=14927999966769665575&hl=en&gl=gb you can use Google Maps API and URL request like
https://maps.googleapis.com/maps/api/place/details/json?cid=&key=
where
<YOUR_CID> = 14927999966769665575and<YOUR_APP_KEY>valid key for your Android app with enabled Google Maps API (on Developer Console same as for URL Shortener API). Fro more details take a look at this answer of Leon. You can useHttpURLConnectionto get response like for point 1:and as the result you should get big JSON with tag
geometryand "subtag"locationand you can get latitude-longitude from it.
For other types URL (not https://goo[dot]gl/maps/fSQSTjDR32m nor https://maps.google.com/?cid=14927999966769665575&hl=en&gl=gb) you should find other schemes for decoding and extracting latitude-longitude.