Alexander Rodionov

GPX walk tracks

Published: Updated:

Tags: tech walk

Screenshot of GPX route in browser using iframe. A route is in Saburtalo district of Tbilisi, Georgia

I exported information about walking tracks from Apple Watch (Apple Health), there is a standard GPX format. There is no way to automate the export as Apple doesn't give a way (privacy blah blah blah). Maybe in the future I will do tracks through some other application where I don't need to unload the whole history with a huge archive every time.

Here is a python script that searches for faraway from current home tracks. (I don't worry about past rental places).

import functools
import shutil
import gpxpy
import tqdm
import gpxpy.gpx
from pathlib import Path
from geopy.distance import geodesic

home_coordinates = 0.0, 0.0  # redacted

def gpx_meters_from_point(
    gpx_path: str,
    point: tuple[float, float],
    min_meters: float = 100,
) -> float:
    with open(gpx_path) as gpx_file:
        gpx = gpxpy.parse(gpx_file)

    meters = None

    for track in gpx.tracks:
        for segment in track.segments:
            for _point in segment.points:
                _meters = geodesic((_point.latitude, _point.longitude), point).meters
                meters = _meters if meters is None else min(meters, _meters)
    if meters is None:
        raise ValueError(f'no points found in gpx file {gpx_path}')
    return meters

Copy to a public folder (which is then copied to the server) tracks that are further than 3000 meters:

gpx_dir = Path('/Users/tandav/Desktop/apple_health_export/workout-routes')
gpx_public_dir = Path('/Users/tandav/docs/files-tandav-me/routes/routes/gpx')
gpx_files = list(gpx_dir.glob('*.gpx'))

for p in tqdm.tqdm(gpx_files):
    if gpx_meters_from_point(p, home_coordinates) < 3000:
    shutil.copy(p, gpx_public_dir /

There is which has ability to render gpx filex from your server in iframe . But you have to setup CORS headers. Here is headers for Caddy: {
    root * /srv

    @gpxFiles {
        path *.gpx
    header @gpxFiles Access-Control-Allow-Origin ""

    file_server {

The list of my walk tracks is at . A screenshot of some walk track is at the beggining of the post.