KML to GeoJSON converter
Take placemarks from Google Earth or Google My Maps to a web map: get a GeoJSON FeatureCollection for Leaflet, MapLibre or an import. Free, and no account needed.
Convert KML to GeoJSON online, in your browser
The Spatibase KML to GeoJSON converter reads a KML or KMZ file with the open-source togeojson library and writes a GeoJSON FeatureCollection in your web browser. What carries over:
- Every placemark as a feature. Points, lines, polygons and Google Earth tracks, with altitude where the KML has it.
- Its data as properties. Name, description as plain text, the folder path, ExtendedData fields and the style colours.
- No upload. The file is read on your computer, up to 50 MB, free and without an account.
How to convert KML to GeoJSON
- Export the KML. Google My Maps: the three-dot menu by the map title → Export to KML/KMZ. Google Earth Pro: right-click a folder in Places → Save Place As.
- Drop the
.kmlor.kmzon the box above, or press Choose a file. No file at hand? Open the sample. - Check the map and the notes: image overlays and network links are counted there, because GeoJSON can’t hold them.
- Press Download GeoJSON for a
.geojsonfile, or Copy GeoJSON to paste the FeatureCollection into your code. - Load it in Leaflet with
L.geoJSON(data), add it as a MapLibregeojsonsource, or import it into a Spatibase project.
What the GeoJSON keeps from your KML
| What | What happens |
|---|---|
| Points, lines, polygons | GeoJSON Point, LineString and Polygon, holes included, in the same longitude and latitude. |
| MultiGeometry | A GeometryCollection, even when every part is the same kind. Some tools, the Spatibase importer among them, take only MultiPoint, MultiLineString or MultiPolygon. |
| Altitude | Kept as a third coordinate. My Maps writes 0 everywhere, so its files come out as [lng, lat, 0]. |
| Name and description | name and description properties. HTML in a description becomes plain text, so links and images in it are lost. |
| Folders | A folder property with the path, such as Trip / Day 1. The features themselves are one flat list. |
| ExtendedData | One property per field. Plain <Data> values are strings ("1.3"); typed SchemaData keeps numbers as numbers. |
| Styles | Properties: fill, stroke, stroke-width, fill-opacity, icon, icon-color and the like, plus styleUrl. |
| Placemark id | The feature’s id. |
| Times | A <TimeStamp> becomes a timestamp property and a <TimeSpan> a timespan with begin and end. A gx:Track keeps its point times in coordinateProperties.times. |
| Image overlays and network links | Skipped, with a count in the notes. Linked data online isn’t fetched. |
| Icons and photos inside a KMZ | Not included. The icon property keeps the path, such as images/icon-1.png, which no longer points anywhere. |
KML and GeoJSON: same coordinates, different model
No reprojection needed. Both formats store WGS 84 longitude, latitude and optional altitude. The text 2.174356,41.403629,0 in a KML becomes the array [2.174356, 41.403629, 0], number for number.
What changes is how the data around the coordinates is organised:
- Folders flatten. KML nests placemarks in folders; a GeoJSON FeatureCollection is one list. The path survives as the
folderproperty, so you can filter on it. - Styles become properties. KML keeps colours in shared
<Style>blocks. togeojson copies them onto every feature as simplestyle keys, which geojson.io draws as they are and MapLibre can use in data-driven paint. - Values arrive as strings. A KML
<Data>value is text, so1.3reads as"1.3". Only a<Schema>with a type keeps numbers; convert the others withNumber()or in QGIS.
Need a lean file? Style keys and styleUrl add bytes to every feature. Delete what you don’t draw before shipping it to a browser, and check the result with the GeoJSON validator on this site if another tool refuses it.
Convert KML to GeoJSON in JavaScript
@tmcw/togeojson, the library this page uses, works in the browser and in Node.js. It needs a parsed XML document:
import { kml } from '@tmcw/togeojson'
import { DOMParser } from '@xmldom/xmldom' // only in Node.js; browsers have DOMParser
const doc = new DOMParser().parseFromString(kmlText, 'text/xml')
const geojson = kml(doc) // a FeatureCollection
console.log(geojson.features.length)Watch the descriptions. A CDATA description comes back as an object { "@type": "html", value }, not a string. This page turns it into plain text; your code should do the same or render it carefully.
For a KMZ, unzip it first, for example with fflate’s unzipSync, and pass doc.kml (or the first .kml in it) to kml(). Use kmlWithFolders() instead of kml() to keep the folder tree.
Questions about converting KML to GeoJSON
How do I convert KML to GeoJSON in JavaScript?
Parse the KML with DOMParser (xmldom in Node.js) and pass the document to kml() from @tmcw/togeojson. It returns a FeatureCollection. For a KMZ, unzip it first and read the doc.kml inside.
Why does the GeoJSON have fill, stroke and styleUrl properties?
They are the KML’s styles. togeojson copies each placemark’s colours and icon onto its feature as simplestyle properties, which geojson.io and other simplestyle-aware tools draw directly. Delete them if your map styles the data itself.
Are KML folders kept in GeoJSON?
As a property, not as structure. GeoJSON has no folders, so all placemarks go into one FeatureCollection and each feature gets a folder property with its path, such as Trip / Day 1. Filter on it to rebuild the groups.
Why are my ExtendedData numbers strings in the GeoJSON?
KML Data values are plain text, so a value like 12 arrives as "12". Fields declared in a Schema with a type such as int or double stay numbers. Convert the rest in your code, or fix the types after importing.
Why do my GeoJSON coordinates have a third number?
It is the altitude from the KML. Google My Maps writes 0 for every point, so its files give [longitude, latitude, 0]. RFC 7946 allows a third value and web maps ignore it, so you can leave it or strip it.
Can I convert a Google My Maps KMZ to GeoJSON?
Yes. The KMZ is unzipped in your browser and the KML inside is converted, with every layer’s places and your table columns. The marker icons packed in the KMZ aren’t part of the GeoJSON.
Moving the places into Spatibase? Read how to import your data. Need another pair of formats? The GIS file converter converts between all of them.