Skip to content

Instantly share code, notes, and snippets.

@avi-c
Last active May 12, 2021 18:14
Show Gist options
  • Save avi-c/9ba7e78b996973dc95c1898b2bfcae9d to your computer and use it in GitHub Desktop.
Save avi-c/9ba7e78b996973dc95c1898b2bfcae9d to your computer and use it in GitHub Desktop.
Recipe for exporting KML for routes from My Maps to a GPX file
Go to My Maps in google maps
In one of your Maps, add a turn by turn directions step for the route you want
Right click the top level My Maps window that contains the steps
Select "Export as KML"
Check the KML box and save the file
Open downloaded file in BBEdit or other powerful text editor
Copy out only the portion of the file that is the long list of coordinates and place it in it's own file without the rest of the KML.
In BBEdit, use the find regular expression: (.*?),(.*?),0 and the replace regular expression: <wpt lat="\2" lon="\1"/> to transform the KML coordinate representation into the GPX waypoint format needed by Xcode
Prepend the GPX JSON tags in the following 2 lines:
<?xml version="1.0"?>
<gpx version="1.1" creator="Xcode">
Append the close of the tag to the end of the file: </gpx>
Save as a copy with a .gpx extension
Import to an Xcode project
Edit the simulator scheme to specify your gpx file as the source for location simulation. It will be listed in the dropdown menu.
Run on the device
Core Location will start emitting the coordinates automatically. This will effect your app as well as the other apps like Apple Maps that are built into the simulated device.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment