GMapToGPX

Convert Google Maps Data to GPX

Version 6.4k: 2014.02.12

The Google Maps API is great, but it doesn’t have an
easy way to export data in GPX
format. This bookmarklet is my attempt at a hack to get information out of
Google Maps and into GPX, suitable for loading on a GPS.

This bookmarklet can create a GPX file based on driving directions, an address search or a local search. The GPX file will contain a route, a single waypoint, or up to ten waypoints, respectively. The code for extracting waypoints from local search originally came from this page.

If you’re looking for a utility to display GPX files in Google Maps, I recommend GPS Visualizer.

Instructions:

Firefox: Drag the following link to your browser’s bookmark toolbar.
Internet Explorer: right-click on the following link and “Add to Favorites…”
This is the link:
GMapToGPX

Go to Google Maps and get some search results. Here are some to test with:

A GPX file should be displayed over the map. Copy and paste it into a file on your hard drive. (Save it as a plain text file, using Notepad, TextEdit, emacs, or whatever your favorite text editor is. If possible, save it with the extension “.gpx”, but “.txt” ought to work, too.)

Load the GPX file into your GPS or mapping software and see what happens.

Upgrade Instructions:

In most cases, upgrades should happen automatically, without any action required on your part.

In the event that a new version has been released but it’s not working for you, check the version number at the top of this page, then click on this link.

If the version number at that link is the same, you should now be upgraded. If not, force a refresh of the page by holding down shift as you click “reload”. The version number should change to match.

If you installed the bookmark prior to February 12, 2014, you should remove it and re-add it. I’ve changed where it pulls the script from, and the only way to get that change is to re-get the bookmarklet.

Notes:

Navigate at your own risk. If a GPX file produced by this code directs you into oncoming traffic or over a cliff, don’t sue me.

I develop and test with Firefox, and try to test with Internet Explorer. Other browser may or may not work.

For driving directions, the “Route”, “Track” and “Points” types only place waypoints at the numbered turns, not at every point Google uses to draw the route. Since roads aren’t necessarily straight, the GPX route can be way off (although the waypoints themselves should be accurate). The “Full” type creates a track log of every point in the route, following the curves of roads. This can be prohibitively large, as I’m not doing anything to filter out points that don’t add significant detail. Maybe that’ll come next.

This is somewhat dependent on the internal workings of Google Maps, and may break the next time they update.

2005.08.03 – Confirmed to work with maps.15.js

2005.08.03 – v3.2 – Updated to work with local.google.com

2005.08.08 – Confirmed to work with maps.16.js

2005.08.18 – Confirmed to work with maps.17.js

2005.10.02 – v3.3 – Fixed a bug with local search, confirmed with maps.21.js

2006.02.17 – v4.0b – Updated to work with maps2.37.js, a fairly major overhaul. New features: full driving directions track log containing all points in the route, not just the turn points; appears to work with Google Maps UK. Not tested against any browser but Firefox 1.5.0.1 on Mac OS X.

2006.04.04 – v4.7 – Nope, that didn’t work. Updated to work with maps2.44.js. Tried a different method of future-proofing. Weird Safari problems; I’ll try to address those in the next version.

2006.04.05 – v4.8 – I think I fixed the Safari problem. It should work now with Firefox, Safari and IE (although you still have to click on the permalink first in IE [as of version 5.0, you no longer have to do this in IE]). I’ve only tested Firefox 1.5/Mac, Safari, and IE6/Win, and not much testing at that.

2006.04.14 – It looks like they’ve updated to maps2.45a.js (including a cool inset window in the lower right), and the bookmarklet still works. A red-letter day for me; this is the first time a version of GMapToGPX has continued to work across back-end updates.

2006.09.14 – v4.12 – Updated to work with maps2.63.js, and fix a bug with single address search results.

2006.10.11 – v4.13 – Updated to work with maps2.65.js. Includes fix for gmap-pedometer-alike sites, as mentioned in the comments. Minimal testing, as it’s being updated at 1:15 in the morning.

2006.12.15 – v4.14 – Updated to work (mostly) with maps2.70.js. Still needs work in order to add route points for milestones in a multi-destination driving route. Not fully tested, but works for me.

2007.03.05 – v4.15 – Updated to address maps2.75.js, which changed a variable that hadn’t been changed in probably a year. Still need to work on multi-point routes, but basic functionality should be restored.

2007.03.22 – v4.16 – Updated to work with maps2.76.js. Now, instead of spitting out bad info for multi-destination routes, spits out good information for only the first segment in a multi-destination route. Still have to think about how to rewrite it to deal with multiple destinations.

2007.03.22 – v4.17 – Updated to work with maps2.77.js. I need to figure out how to fix it so it doesn’t break with each update again. Multiple destinations still don’t work, either.

2007.04.23 – v5.0 – Major update. Rewrote all the code for extracting driving directions, and a good chunk of the points of interest extraction code as well. Uses fewer calls to non-API internals, so it shouldn’t break as often when Google updates maps*.js. Also fixed the display problem where UI elements such as scroll bars were showing through the GPX textarea. Should work on Firefox and IE; haven’t tested on anything else.

2007.05.01 – v5.1 – They must be doing this on purpose. For no apparent reason, they changed the way driving directions are quoted in maps2.79.js, which broke the bookmarklet. I’ll have to come up with better regular expressions. Fixed, for now.

2007.05.21 – v5.2 – Updated to work with gmaps version 81 (no longer named maps2.version.js). New features: descriptive route and destination comments. Start of route still gets “Head east on…” instead of the address, though.

2007.06.13 – v5.3 – Maybe upgraded to work with version 82, although while I was working on it they seem to have rolled back to 81, so I’m not sure.

2007.06.19 – v5.3e – 5.3a through 5.3e are mainly small bugfixes. 5.3e adds better handling of “My Maps” style maps, with a download link for the KML and a pointer to GPSVisualizer.

2007.07.13 – v5.4 – Added preliminary support for yelp.com. Can’t do “nearby businesses” listings, but should be able to handle searches and individual listings.

2007.08.21 – v5.4a – Fixed to address new obfuscation style in version 87. No new features.

2007.10.09 – v5.5 and 5.5a – Incorporated a fix from Kyle Yost to seriously increase performance when displaying the “Full” list of points. Also fixed a bug in “Full” with milestone descriptions being off by one, and with double-encoding of ampersands. Potentially fixed a character encoding problem for international versions, although I haven’t been able to test whether it works. It works for me, but then again, it did before, too.

2007.10.16 – v5.6 – maps.js version 91 has a new way of indexing route segment points and descriptions. I think v5.6 addresses this.

2008.07.31 – v6.0a – Completely redid the gmaps driving/walking direction extraction, addressing maps.js version 121. I should do that for the gmaps POIs, too, but I’ll leave that for 6.1, since it still works with the old code. (6.0 only existed for a few minutes, and screwed up “My Maps” support.)

2008.11.23 – v6.3 – Works with gmap-pedometer again, for now. And includes a fix so that if you’ve saved the route, it will include the permalink, instead of always saying that it’s unavailable. It won’t save the route for you, though. Also, with the new auto-routing enabled, there may be many more “turns” in the route than you expect. Disable auto-routing if this annoys you.

2008.11.24 – v6.3a – Addresses a change in maps.js version 138f. They’ve added an array named “trips”, but I can only ever get the first element of it populated. It looks like maybe they’re planning to let people have multiple trips on one page, which would potentially mean a larger rewrite of my code. I guess I’ll address that if it happens.

2009.03.09 – v6.4 – Somewhere between 138f and 149f, they changed how points of interest are stored. I don’t remember if they’ve ever done that before. 6.4 takes that into account.

2009.03.10 – v6.4a – I didn’t test very well, and missed that 6.4 only worked in certain cases. 6.4a should work better.

2009.03.20 – v6.4b – Quickly hacked back in support for sites which worked like gmap-pedometer, prior to v6.3. Should make usatf.org work again, maybe.

2010.10.17 – v6.4c – Minor change to page encoding detection. There’s almost certainly a way to do it that doesn’t involve scraping the html, but this way of fixing it was quick. Should solve the “invalid xml/gpx” problem.

2010.11.18 – v6.4d – Been a while since I really dug into how this worked, so it took me a while to get a fix out, sorry. This should fix problems introduced by a back-end change they made a few days ago. I’ve done minimal testing, because I’m going to put more effort into a writing new major version which scraps most of how it currently works.

2010.12.25 – v6.4g – Hm, I must have forgotten to update the page when I added 6.4f. Oh well. 6.4g fixes a bug in a regular expression (I hope) which was causing only the first turn in any route to get displayed.

2011.07.01 – v6.4i – Huh, I forgot to update at 6.4h, too. This update removes the code which checked for “view as kml” on a “my maps” page, since those don’t exist in the same way any more. I’ll work more on it later, but this should fix the problem where it didn’t work at all because of that.

2011.07.12 – v6.4j – Added support for “My Places” back in, based on the URL of the link, rather than looking for a “view in google maps” icon. I have no idea if this will break something else, but my quick set of tests seems to show it working.

2014.02.12 – v6.4k – No change in the script, but a change to the bookmarklet. You will need to remove and re-add the bookmarklet to get this change, which moves the hosting of the script to an https site. This should fix the problem with nothing happening on the https version of Google Maps. There are no other changes.

Read 1,602 comments

Comment navigation

Last week I bought the Sygic Navigation dvd, but because the folks of Sygic were not capable of activating my application in time (after 2 weeks ?!), I needed another solution for helping me to find my way to Paris.
Luckily I found this excellent bookmarklet that in combination with Maps(-) for Android give me the possibility to use my smartphone as a almost perfect navigation tool. Thanks a lot !

Non English Character Issue:
Those of you who are trying to make gpx files from google maps with characters such as åäö (or equiv) and then importing them to MapSource: Try edit the gpx file and replace the åäö with aao, then it should work just fine to import it to MapSource and then transfer routes to your Garmin device.
Good luck!

Btw: Thanks for providing this software and putting effort into maintaining it. I really appreciate it.

For some reason, I have to put it through RouteConverter and save again as 1.1 gpx for it to show on my GPSMap 62st. If I don’t do that, the route isn’t visible in Route Manager. There’s not much of a difference in the file, if I find out what exactly causes this, I’ll post.

I have not tried this on the road yet, but I already wanted to say THANKS. I go on 100-150 mile bike rides, and like to change my route up a lot. Google Map’s bike option made this a lot easier, but I had no good way to get the route onto my GPS until I say your utility.