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.

Drop a KML or KMZ file here

Download the sample

Your file stays on your computer: nothing is uploaded.

In short

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

How to convert KML to GeoJSON

  1. 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.
  2. Drop the .kml or .kmz on the box above, or press Choose a file. No file at hand? Open the sample.
  3. Check the map and the notes: image overlays and network links are counted there, because GeoJSON can’t hold them.
  4. Press Download GeoJSON for a .geojson file, or Copy GeoJSON to paste the FeatureCollection into your code.
  5. Load it in Leaflet with L.geoJSON(data), add it as a MapLibre geojson source, or import it into a Spatibase project.
What’s kept

What the GeoJSON keeps from your KML

WhatWhat happens
Points, lines, polygonsGeoJSON Point, LineString and Polygon, holes included, in the same longitude and latitude.
MultiGeometryA GeometryCollection, even when every part is the same kind. Some tools, the Spatibase importer among them, take only MultiPoint, MultiLineString or MultiPolygon.
AltitudeKept as a third coordinate. My Maps writes 0 everywhere, so its files come out as [lng, lat, 0].
Name and descriptionname and description properties. HTML in a description becomes plain text, so links and images in it are lost.
FoldersA folder property with the path, such as Trip / Day 1. The features themselves are one flat list.
ExtendedDataOne property per field. Plain <Data> values are strings ("1.3"); typed SchemaData keeps numbers as numbers.
StylesProperties: fill, stroke, stroke-width, fill-opacity, icon, icon-color and the like, plus styleUrl.
Placemark idThe feature’s id.
TimesA <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 linksSkipped, with a count in the notes. Linked data online isn’t fetched.
Icons and photos inside a KMZNot included. The icon property keeps the path, such as images/icon-1.png, which no longer points anywhere.
Formats

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 folder property, 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, so 1.3 reads as "1.3". Only a <Schema> with a type keeps numbers; convert the others with Number() 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.

Do it in code

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.

FAQ

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.

Talk to us

Not sure it’s a fit? Let’s find out

Tell us about your use case and what you need, from data model to security and deployment. In 30 minutes we’ll look at it together and tell you honestly if we can help.

Or write to hello@spatibase.com.