GPX2GeoJSON demo page

Small and fast GPX to GeoJSON converter library for JavaScript


Project maintained by M-Reimer Hosted on GitHub Pages — Theme by mattgraham

GPX to GeoJSON file conversion

Here you can directly convert a GPX file to GeoJSON using the GPX2GeoJSON library.

Note: The file never leaves your PC and is directly converted inside your browser.

Example code for converting a string with GPX content in variable text to pretty printed JSON in variable jsonstr using the GPX2GeoJSON library:
const json = GPX2GeoJSON.fromText(text, {
  "addAltitude": ADDALT.checked
});
const jsonstr = JSON.stringify(json, null, "  ");

Usage to display GPX files on Leaflet maps

This was actually the main goal for the GPX2GeoJSON project. Leaflet only directly supports GeoJSON to create feature layers. GPX2GeoJSON allows you to use GPX files just as easy as GeoJSON files. This allows to mix GeoJSON and GPX on one map while always having the exact same interface for all layers.


Example code for using a GPX file inside a L.geoJSON Leaflet layer:
GPX2GeoJSON.fromURL("fells_loop.gpx").then((geojson) => {
  L.geoJSON(geojson).addTo(map);
});