Skip to content

Create a folder of OSMAnd GPX files from a google my maps map

Notifications You must be signed in to change notification settings

tmusolf/GoogleMapToOSMAndGPX

Repository files navigation

GoogleMapToOSMAndGPX

Creates a folder of OSMAnd style GPX files from a google my maps map (GMap)

If you do trip planning in GMaps this utility will export the track and waypoint information from a GMap and create a folder of OSMAnd style GPX files.

There is a command line utility and a GUI wrapper that provides a simple graphical user interface to execute the utility.

Options

Both the utility and wrapper can be run as python utilities or you can use the provided Windows executable (exe) files, so python is not required.

The utility uses the GMap MapID to directly export the map's data in KML format and then it converts it to OSMAnd style GPX files. Both tracks and waypoints are converted along with the appropriate description, icon symbol, icon color, track color and track width. For a given map each track is put in its own GPX file and all waypoints are put in a single GPX file. Optionally, the GMap layers will be preserved, creating a separate subdirectory of GPX files for each GMap layer.

Example of a GMap and OSMAnd equivalent

Here is a small section of a GMap and the corresponding GPX data created by this utility displayed in OSMAnd

Options Options

Command Line Syntax

py GoogleMapToOSMAndGPX.py <map_id> <gpx_path> <width 1-24> -t <transparency 00 to FF> -s <split type> -i <split interval miles/seconds> -a -e
Parm Long Parm Description
map_id Required: The GMap id of the map to be converted. The map_id is found in the URL when the map is being displayed in a browser. It the string of characters between mid= and & in the map url. The map must have sharing enabled.
gpx_path Required: Path name for the created GPX files. If it doesn't exist a folder of this name is created. If the folder exists any existing files are NOT deleted, but files with the same names will be overwritten.
-t --transparency Transparency value to use for all tracks. Specified as a 2 digit hex value without the preceeding "0x". 00 is fully transparent and FF is opaque.
-a --arrows When present, OSMAnd will display directional arrows on a track.
-e --ends When present, OSMAnd will display start and finish icons at the ends of the track.
-s --split Display distance or time splits along tracks. Accepted values are: no_split, distance, time. Default: no_split NOTE: The split and interval tags appear to be ignored by OSMAnd when placed in a track GPX file. The XML is identical to what OSMAnd generates when you edit a track's appearance to turn on splits and export the track.
-i --interval Distance in miles or time in minutes to display splits on track. Split type (-s) must also be defined. Default: 1.0)
-w --width If present, this track width is used for all track widths, overiding values found in the KML file.
-l --layers If present, will create a subdirectory under the gpx_path for each layer in the GMap file. Each of these layer subdirectories will contain a GPX file for each track and one for all the waypoints.

Google Map Layers

A google map can have layers as a way to organize the waypoints and tracks. By default, this structure is ignored. A directory <gpx_path> is created containing a single GPX file for all waypoints found in the GMap and one GPX file for each track in the GMap.

Using the -l parameter the layer organization is preserved. A subdirectory, named after the layer, is created under <gpx_path>for each layer. Each of these subdirectories will contain a GPX file for each track in the layer and one GPX file containing all of the waypoints in the layer.

Using the GPX files with OSMAnd

To use these converted GPX files in OSMAnd they need to be placed in the appropriate OSMAnd tracks folder on your phone. Transfer the folder and it's GPX files to your phone and then use a file manager app to copy the entire folder to the Android/media/net.osmand.plus/files/tracks directory. You can also create folders under the tracks directory to contain these folders. For example, ...tracks\Germany & ...tracks\Sweden. This type of organization can make it easier to find and manage these tracks.

To remove the GPX files from OSMAnd you can use a file manager app or OSMAnd My Places to delete individual GPX files or the entire folder.

NOTE: As of V4.8.6 the OSMAnd import feature only allows you to import a single GPX file at a time, not a folder of GPX files. In addition, if you use the OSMAnd import feature you will lose a track's color and line width and they will be imported with OSMAnd default values.

NOTE: Starting with Android 11 there are enhanced file protection protocals put in place that prevent you from accessing the files in the Android/obb/net.osmand.plus folders. You can change this location to one that is accessible by other Android applications by going to settings/OSMAnd settings/Data storage folder and selecting manually specified /storage/emulated/0/Android/media/net.osmand.plus/files.

Making a GPX file visible

Once the folder is transfered into OSMAnd you can make all the GPX files in the entire folder visible/not visible as a group or you can select them individually. When they are made visible the tracks will display with the same line color as you specified in the original GMap. Waypoints will be converted to an OSMAnd equivalent icon and color using a translation dictionary in the GoogleMapToOSMAndGPX utility.

From the OSMAnd main menu select the My Places / Track tab and navigate to the folder containing your GPX files. Touch the folder you wish to open up. In this example the Kayak folder.
Options


In this example the kayak folder contains another layer of folders, one for each river. Select the elispis next the folder you want. In this example, Tuolumne is chosen.
Options


Select the Show all tracks on the map option.
Options


Now a list of the GPX track files and waypoint files are displayed. Check all the listed GPX files you want displayed and select APPLY.
Options


At this point you can navigate back to your map and the tracks and waypoints from the GPX files will be visible.
Options


Here is a sample of the corresponding GMap used in this example:
Options


Because each track is in its own GPX file it will be individually selectable in OSMAnd. Once selected you can see the track's description, length and other attributes.
Options


NOTE: If an icon is not translated or translated as you wish you can update the translation dictionary in the python utility code.

Making a GPX file not visible


To make a folder of GPX files not visible nagivate to the appropriate folder, as shown above, select Show all tracks on the map then uncheck or deselect the files you want to make not visible and finally select apply.
Options

Windows Executables

There are two .exe files provided which are windows 64 bit executables. They are standalone files and do not need to be installed, they can be run directly. You do not need to use or install python to run these exe files.

GoogleMapToOSMAndGPX.exe is the command line utility itself and GoogleMapToOSMAndGPX-gui.exe is the graphical user interface (GUI) wrapper that allows you to run the utility via a simple user inteface instead of the command line. For this to work both files must be placed in the same directory.

The first time you run GoogleMapToOSMAndGPX-gui.exe you may receive a windows warning about these files because they don't have an official security certificate. I'm not a professional developer so I don't have one of those. You'll need to select run anyway to get it to execute.

These have been tested on several Windows 10 machines and they run fine, but that's far from an exhaustive test protocol. Your milage may vary.

Python Source Code

I'm not going to go into how to install python and run these utilities. If you're familar with Python on your platform of choice, it shouldn't be difficult.

I used pyinstaller to "compile" the python source code into the Windows executable files. You can use the spec files in Github to drive pyinstaller.

Batch File

There is a batch file example which takes a user created text file containing lines of comma separated paths and GMap ids with optional parameter overides. This file can then be fed to the batch file and it will call the conversion utility once for each line in the file. This is a quick way to update the GPX files from a large group of GMaps without having to do them individually.

GPX Track file example

Here is an example of the GPX XML code created by this utility for a track

<?xml version="1.0" encoding="utf-8"?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:osmand="https://osmand.net" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="GoogleMapToOSMAndGPX V1.1">
  <metadata>
    <desc>Description text to be displayed in OSMAnd</desc>
  </metadata>
  <trk>
    <name>My track name</name>
    <trkseg>
      <trkpt lat="37.5793230067939" lon="-121.966263027862">
        <ele>12.4</ele>
      </trkpt>
      <trkpt lat="37.5793280359358" lon="-121.966279959306">
        <ele>10.4</ele>
      </trkpt>
    </trkseg>
  </trk>
  <extensions>
    <osmand:color>#80F48FB1</osmand:color>
    <osmand:width>12</osmand:width>
    <osmand:show_arrows>false</osmand:show_arrows>
    <osmand:show_start_finish>false</osmand:show_start_finish>
    <osmand:split_type>no_split</osmand:split_type>
  </extensions>
</gpx>

GPX Waypoint file example

Here is an example of the GPX XML code created by this utility for waypoints.

<?xml version="1.0" encoding="utf-8"?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:osmand="https://osmand.net" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" creator="GoogleMapToOSMAndGPX V1.1">
  <wpt lat="37.5793131999671" lon="-121.966220028698">
    <ele>25.6</ele>
    <name>Waypoint name</name>
    <desc>Waypoint description to be displayed in OSMAnd</desc>
    <extensions>
      <osmand:icon>leisure_marina</osmand:icon>
      <osmand:background>octagon</osmand:background>
      <osmand:color>#a71de1</osmand:color>
    </extensions>
  </wpt>
</gpx>

Parting words

I use this utility on a regular basis and it's made importing my custom GMaps so much easier. This is a work in progress as I learn more about OSMAnd's handling of GPX files and its GPX extensions. Feedback and comments welcome.

I'm not python guru so the code structure is probably not totally pythonic.

I'm sharing this in the hope that they are of use to the broader OSMAnd community.

About

Create a folder of OSMAnd GPX files from a google my maps map

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published