简体   繁体   中英

How to get latitude longitude from google map URL

I am building an android application which would store latitude and longitude information from google maps. The application receives the Send/Share intent from Google maps when user chooses location from map and extracts co-ordinates by un-shortening the goo.gl map link (eg http://goo.gl/maps/FcglP ) embedded in intent. This task is easy if the location being shared from google maps is unknown or named "dropped pin". In that case the un-shortened URL looks like

http://maps.google.com/?q=17.50122123,74.12351323&.....

If the location is well known ( http://goo.gl/maps/FcglP ), eg some road, un-shortened URL looks like

http://maps.google.com/?q=Sutarwadi+Baner+Gaon+Rd%2C+Baner&ftid=0x3bc2becfa70b8b3f:0xd210c15f634bcec3&hl=en&gl=us

I have been searching for last three hours about how to extract the co-ordinates from this kind of URL but couldn't find any information. Is there any other method to extract co-ordinates from a given goo.gl map URL? Some already developed library or google API?

2 steps:

function myMap() {

var mapUrl = $('.map').html();
var url = mapUrl.split('@');
var at = url[1].split('z');
var zero = at[0].split(',');
var lat = zero[0];
var lon = zero[1];

var mapProp= {
        center:new google.maps.LatLng(lat,lon),
        zoom:5,
};
var map = new google.maps.Map(document.getElementById("mapL"),mapProp);

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM