0

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)?

Community
  • 1
  • 1
DrAl
  • 70,428
  • 10
  • 106
  • 108

2 Answers2

0

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

Community
  • 1
  • 1
Marcelo
  • 9,387
  • 3
  • 35
  • 40
  • Is it guaranteed all of the waypoints are in the URL? I couldn't convince myself this was true. For example, given this link http://ln-s.net/$azx, there are (if I'm counting correctly) 24 points. The URL seems to contain 20 latitude/longitude values that look reasonable (and two with spn= and sspn= preceding them) that look like they're something unrelated. – DrAl Aug 09 '12 at 20:47
  • Unfortunately I cannot guarantee anything but, I edited the reply adding a breakdown of the link in your comment. I see 24 waypoints, including the 2 endpoints. – Marcelo Aug 10 '12 at 06:22
  • That was similar to my assessment: unfortunately I can see no way to convert (e.g.) "Unknown+road" into a location (hence my counting of only 20 values - it looks like one of these is something about a business search and therefore there are 19 useful points and 5 unparseable ones). I assume the missing information must be in the geocode parameter (and indeed the link you sent suggests this may be true), but there's no obvious way of retrieving this data. – DrAl Aug 10 '12 at 07:01
  • Yes, I see the problem. I tried decoding the 'geocode' parameter with this utility: http://facstaff.unca.edu/mcmcclur/GoogleMaps/EncodePolyline/decode.html but the points that come out do not seem to make any sense. In any case, according to the docs, only a maximum of 8 waypoints are allowed for ordinary users, (23 for business customers). Sorry I couldn't help. :-( – Marcelo Aug 10 '12 at 07:41
  • Thanks for trying anyway! I had suspected it wouldn't be possible from the URL, hence my comment about trying to get to it with a bookmarklet that injects javascript into the Google Maps page after the route is loaded. – DrAl Aug 10 '12 at 09:17
0

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.

Sverrir Sigmundarson
  • 2,453
  • 31
  • 27
  • 1
    Interesting tool, thanks for sharing that. I've just tried out your tool (with this link: https://goo.gl/maps/3wRxvfdwsf22) and it seems to extract all the turns, but not the actual routing information. It's a shame that it doesn't include the control points (where the route has been adjusted), otherwise this method could then regenerate the full path. My use case is similar to yours: I want to generate GPX files with my http://gpx.cgtk.co.uk site - at the moment I work round it by making users redraw their route on my site but I'd love to allow import of an existing route. – DrAl Nov 24 '15 at 15:36
  • Thanks for the kind words. The tool does not plot the adjusted points you're right (they're included as via-points and I haven't figured out how Maps represents that, they're encoded somehow). The important turn points should however be present that would reproduce this route if you use the Google Directions API. If you're interested in pure track-points then the gpsvisualizer.com tool is your best bet. (my tool is a complement to theirs) – Sverrir Sigmundarson Nov 24 '15 at 19:14