how do i decode/encode the url parameters for the new google maps?

后端 未结 3 589
栀梦
栀梦 2020-12-08 17:27

Im trying to figure out how to extract the lat/long of the start/end in a google maps directions link that looks like this:

https://www.google.com/maps/preview#!data

3条回答
  •  攒了一身酷
    2020-12-08 18:12

    Try this.

    function URLtoLatLng(url) {
      this.lat = url.replace(/^.+!3d(.+)!4d.+$/, '$1');
      this.lng = url.replace(/^.+!4d(.+)!6e.+$/, '$1');
      return this;
    }
    
    var url = new URLtoLatLng('https://www.google.com/maps/preview#!data=!1m4!1m3!1d189334!2d-96.03687!3d36.1250439!4m21!3m20!1m4!3m2!3d36.0748342!4d-95.8040972!6e2!1m5!1s1331-1399+E+14th+St%2C+Tulsa%2C+OK+74120!2s0x87b6ec9a1679f9e5%3A0x6e70df70feebbb5e!3m2!3d36.1424613!4d-95.9736986!3m8!1m3!1d189334!2d-96.03687!3d36.1250439!3m2!1i1366!2i705!4f13.1&fid=0');
    
    console.log(url.lat + ' ' + url.lng);

提交回复
热议问题