Convert Google Maps direction URLs to GPX files. Supports shortened URLs, dragged routes, alternative routes, and motorcycle (two-wheeler) mode.
Project description
gmaps2gpx
Convert Google Maps direction URLs to GPX files with a single command.
Features
- Shortened URLs - Paste
maps.app.goo.gllinks directly - Dragged routes - Preserves via-points when you drag a route on Google Maps
- Motorcycle mode - Two-wheeler routing via Google Routes API (great for India/SE Asia)
- Alternative routes -
--shortestpicks the shortest route by distance - Batch convert - Pass multiple URLs at once
- All travel modes - driving, walking, bicycling, transit, motorcycle
Install
# From PyPI
pip install gmaps2gpx
# Or with pipx (recommended - isolated install)
pipx install gmaps2gpx
# From source
git clone https://github.com/prajwalp/gmaps2gpx.git
cd gmaps2gpx
pip install .
Setup
You need a Google Maps API key with Directions API enabled. For motorcycle mode, also enable the Routes API.
# Set it once (add to your .bashrc/.zshrc)
export GOOGLE_MAPS_API_KEY="your_key_here"
Or pass it each time with -k YOUR_KEY.
Getting an API key
- Go to Google Cloud Console
- Create a project (or select existing)
- Enable Directions API (and Routes API for motorcycle mode)
- Create an API key under Credentials
- (Optional) Restrict the key to Directions API + Routes API
Usage
# Basic - paste any Google Maps directions link
gmaps2gpx 'https://maps.app.goo.gl/Mz9Q47fcBMHLa2HB7'
# Save to specific file
gmaps2gpx 'https://maps.app.goo.gl/abc123' -o ride.gpx
# Motorcycle / two-wheeler mode (uses Google Routes API)
gmaps2gpx 'https://maps.app.goo.gl/abc123' -m motorcycle -o ride.gpx
# Pick the shortest route from alternatives
gmaps2gpx 'https://maps.app.goo.gl/abc123' --shortest
# Full Google Maps URL works too
gmaps2gpx 'https://www.google.com/maps/dir/Mumbai/Goa' -o mumbai_goa.gpx
# Walking directions
gmaps2gpx 'https://maps.app.goo.gl/abc123' -m walking
# Batch convert multiple routes
gmaps2gpx URL1 URL2 URL3
# Pass API key directly
gmaps2gpx 'https://maps.app.goo.gl/abc123' -k YOUR_API_KEY
Options
positional arguments:
urls one or more Google Maps direction URLs
options:
-k, --api-key KEY Google Maps API key (or set GOOGLE_MAPS_API_KEY env var)
-o, --output FILE output GPX filename (auto-generated if omitted)
-m, --mode MODE travel mode: driving, walking, bicycling, transit, motorcycle
-s, --shortest fetch alternatives and pick the shortest by distance
-h, --help show help
How it works
- Resolves shortened Google Maps URLs
- Parses origin, destination, waypoints, and dragged via-points from the URL
- Calls Google Directions API (or Routes API for motorcycle mode)
- Decodes polylines into GPS coordinates
- Generates a GPX 1.1 file with track points and waypoint markers
Publishing to PyPI
One-time setup:
# Install build tools
pip install build twine
# Create a PyPI account at https://pypi.org/account/register/
# Generate an API token at https://pypi.org/manage/account/
To publish:
# Build the package
python -m build
# Upload to PyPI
twine upload dist/*
# You'll be prompted for credentials:
# Username: __token__
# Password: pypi-YOUR_API_TOKEN
After publishing, anyone can install with:
pip install gmaps2gpx
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gmaps2gpx-1.0.0.tar.gz.
File metadata
- Download URL: gmaps2gpx-1.0.0.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb36b40ef51ea7bd80610a36c011c8cc1c2b3709e42dd1b0e0c4bb31768ebc44
|
|
| MD5 |
7ff6c73f50fb7f27b142ee69b6a41ee7
|
|
| BLAKE2b-256 |
c13e7afff4d6fbb32b63a16b1516463def9a72097281698604aa93c03cdd963c
|
File details
Details for the file gmaps2gpx-1.0.0-py3-none-any.whl.
File metadata
- Download URL: gmaps2gpx-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32bbead16617150a1b16abe1dfae43f8f30576d3a93d85a6af7f10c592462a94
|
|
| MD5 |
e46f2f71609bd63dc0243418891c0660
|
|
| BLAKE2b-256 |
740bdeab8f4578d005f9eea7e343f63965633f0a81e232dc25cef0cb8de6f8fc
|