简体   繁体   中英

Extract DirectionsResult from Google Maps URL

I'm in the process of making a (new version of a) tool that converts directions from Google Maps into GPX files. The test-version of this is working reasonably well: it uses the Google Maps Javascript API (v3) to embed a map on the website and you can create your route using the same sort of methods as you would on the main Google Maps page.

However, a (possibly common) use case for this site (and the way the previous version worked before Google changed their undocumented &output=kml interface !) is for people to plan their route on the main Google Maps and save the link (like this one ) for future use. They would then paste this link into the site and it would convert that route into a GPX file.

Is there any way to extract a DirectionsResult from a Google Maps URL or the main Google Maps page (presumably either by sending the URL to the Google Maps API for parsing or by using a bookmarklet on the page itself)?

The DirectionsResult object is not in the link that users can get from maps.google.com. However the endpoints, and any eventual waypoints are, and given the same endpoints the routing engine should produce the same result.


Edit

Below is the URL from your link disassembled. (I left out the ampersands). I count 24 waypoints, (including 2 end points). The only mistery is in the 'geocode' parameter.

https://maps.google.co.uk/maps?
saddr=Unknown+road  //1
daddr=51.59782,-2.08838 //2
+to:51.74885,-1.94076   //3
+to:51.89255,-1.87129   //4
+to:51.82571,-1.79752   //5
+to:B4020   //6
+to:51.8183,-1.41985    //7
+to:51.72228,-1.43255   //8
+to:51.6239798,-1.3071767   //9
+to:B4001   //10
+to:51.34501,-1.34062   //11
+to:51.35822,-1.12071   //12
+to:51.31526,-1.02412   //13
+to:51.08784,-1.62069   //14
+to:51.29048,-1.73004   //15
+to:51.21761,-1.98589   //16
+to:51.397,-2.13542 //17
+to:Gloucester+Rd%2FA46 //18
+to:51.69001,-2.22161   //19
+to:51.81753,-2.07376   //20
+to:Southam+Ln  //21
+to:52.06075,-1.95706   //22
+to:52.1244,-1.64775    //23
+to:Unknown+road    //24

hl=en
sll=51.421477,-1.238708
sspn=0.804988,2.425232
geocode=Fe3uEwMd_znk_w%3BFfxREwMdRCLg_ylHpOCHwW1xSDHRnVfMI4sNEw%3BFfKfFQMd6GLi_ymv2fIl5RVxSDFAVssIXhupMA%3BFUbRFwMdRnLj_yk75kbkvCNxSDHw_q6FJ4sNEw%3BFS7MFgMdcJLk_ykD5mQuJTtxSDHgWC3MI4sNEw%3BFdYZFgMd7WHn_w%3BFTyvFgMdtlXq_ymvJFBAac52SDFgrE_MI4sNEw%3BFSg4FQMdGiTq_ymp-yJAfMl2SDGhNuPMI4sNEw%3BFSu4EwMd2A3s_ylFwdt-trl2SDF0LAm28EHw6A%3BFZq5EgMdyvfo_w%3BFXJ2DwMdNIvr_yn381tpGqh2SDHyCAjGbJ6ylw%3BFQyqDwMdOubu_ykbWNAI8p92SDEglIatLa4OEw%3BFTwCDwMdiF_w_yl5ij0IOid0SDHaHrE5DElJBg%3BFeCJCwMdLkXn_yl_I3MRXvFzSDEA3pytLa4OEw%3BFXChDgMdCJrl_ynf-pMZIeNzSDHByGFPQfQQEw%3BFcqEDQMdnrLh_yk5pddkcdxzSDGx1yhQQfQQEw%3BFYhBEAMdhGrf_yn9N9ICjnxxSDESypqQN61DoA%3BFczUEAMdiOLb_w%3BFRq6FAMd1hne_ylrQ8v5YQtxSDFgr3TNI4sNEw%3BFTqsFgMdYFvg_ykTvsctjBBxSDGlvLvm_K2I9g%3BFWphGAMd4rrg_w%3BFU5iGgMdPCPi_ym5URqPnOBwSDGQ6kLMI4sNEw%3BFfBaGwMdetvm_ylznhar3NNwSDFuGBHuA73ljw%3BFeB7GQMdItPn_w
mra=dpe
mrsp=11
sz=9
via=1,2,3,4,6,7,8,10,11,12,13,14,15,16,18,19,21,22
t=m
z=8

Here's an explanation of map parameters, (best I know of): http://mapki.com/wiki/Google_Map_Parameters

The new Google Maps does not guarantee that all route points exist in the URL, this is specially true for the shortened urls.

A while back I wrote a tool that converts the new Google Maps format into a gpx file.

http://labs.coruscantconsulting.co.uk/garmin/gpxgmap/convert.php

It can also return a JSON response.

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