Dev.to WebDev 🛠 Dev 👁 2 📖 4 min read

How to Convert Google Earth KML to Clean GeoJSON in Your Browser

Google Earth and Google My Maps are great for drawing boundaries, plotting delivery zones, and pinning custom waypoints. However, KML (Keyhole Markup Language) is bulky XML designed primarily for 3D globe viewers. Moder

Google Earth and Google My Maps are great for drawing boundaries, plotting delivery zones, and pinning custom waypoints.

However, KML (Keyhole Markup Language) is bulky XML designed primarily for 3D globe viewers. Modern web mapping stacks like Leaflet, Mapbox GL JS, OpenLayers, and Turf.js do not parse KML natively without bloated plugins. They run on GeoJSON (RFC 7946), which stores geographic vector features as lightweight JSON arrays.

Converting KML to GeoJSON typically involves installing command-line tools like GDAL (ogr2ogr), configuring Python environments, or uploading proprietary map layers to untrusted online conversion sites.

Fortunately, you don't need desktop GIS software or cloud converters to transform your coordinates.

Here's how you can parse KML layers, preserve custom attributes, and export clean GeoJSON directly inside your browser.

The Friction with Converting KML to GeoJSON

KML files present specific formatting challenges that break generic XML-to-JSON converters:

  1. Coordinate Order Inversion: KML stores coordinates as comma-separated longitude,latitude,altitude text strings inside <coordinates> blocks. Standard GeoJSON requires strict numeric arrays [longitude, latitude] (or [longitude, latitude, elevation]).
  2. Nested Folders and Placemarks: Google Earth maps frequently nest geographic entities inside complex <Document> and <Folder> hierarchies, which can lose organizational structure if flattened naively.
  3. Custom Attribute Stripping: Many converters grab only geometry points and discard critical business data stored inside <ExtendedData>, such as parcel IDs, contact names, and category tags.
  4. Complex Polygons: Features like polygons with inner holes (<innerBoundaryIs>) or multi-geometry features (<MultiGeometry>) often break when translated by basic scripts.

A Browser-Based KML to GeoJSON Converter

Instead of setting up local Python or GDAL pipelines, you can run coordinate parsing directly in client-side memory.

I've built a free, browser-based GIS utility to handle this conversion:

👉 Try the Free Online KML to GeoJSON Converter

Privacy-First Architecture

The converter parses XML and builds geometries entirely through client-side JavaScript using the browser's native DOMParser.

This means:

  • Proprietary boundary maps, private land survey coordinates, and client delivery zones are never transmitted to any external server.
  • Processing happens instantly in local memory with zero file size upload bottlenecks.
  • The output strictly complies with the RFC 7946 standard, making it ready for Leaflet, Mapbox, QGIS, or geojson.io.

Step-by-Step: Converting KML to GeoJSON

1. Load Your KML Map File

Open the KML to GeoJSON Converter:

  • Drag and drop your .kml file into the upload drop zone.
  • Alternatively, paste raw KML XML directly into the text input area.
  • If you want to preview how the tool structures output first, click Load Sample KML.

Note on KMZ files: KMZ files are compressed ZIP archives. If you have a .kmz export from Google Earth or My Maps, rename the file extension to .zip (or unzip it with any archive tool) to extract the doc.kml file inside, then upload that .kml file.

2. Configure Output Precision and Settings

Adjust your export preferences using the options toggles:

  • Precision: Select 6 decimals (~0.1m) for standard web mapping to keep file sizes lean without sacrificing street-level precision, or select Full precision for high-accuracy surveying.
  • Keep Altitude (Z): Keep this unchecked unless your web mapping application explicitly requires 3D elevation coordinates.
  • Pretty-Print JSON: Keep checked for clean, formatted indentation, or uncheck to produce a minified single-line GeoJSON payload for faster web loading.

3. Verify Geometry and Attributes

Once loaded, the tool displays live counts for Points, Lines, and Polygons, and automatically projects a 2D wireframe preview on an HTML5 canvas.

Key-value pairs stored inside <ExtendedData> (<Data> and <SimpleData>) are preserved and mapped directly into each GeoJSON feature's properties dictionary alongside standard name and description fields.

4. Export Your GeoJSON

  • Click Download GeoJSON (.geojson) to save the file locally.
  • Or click Copy GeoJSON to paste the FeatureCollection directly into your mapping codebase, Leaflet layer, or geojson.io.

3 Quick Tips for Clean GeoJSON Maps

1. Optimize Coordinate Precision for Web Apps

Latitude and longitude with 6 decimal places gives accuracy down to approximately 10 centimeters (4 inches). Retaining 10 or more decimal places rarely adds useful geographic precision for web maps, but drastically inflates JSON download sizes for mobile users.

2. Minify for Production Use

When bundling GeoJSON datasets into production React, Vue, or mobile apps, uncheck pretty-printing before downloading. Stripping indentation whitespace can reduce file weight by up to 30%.

3. Inspect Complex Polygons with Holes

If your map includes donut-shaped boundaries (such as a county boundary excluding a city center), verify that your downstream mapping engine supports GeoJSON multi-ring polygons (outerBoundaryIs followed by one or more innerBoundaryIs rings).

Final Thoughts

Converting geospatial layers from desktop globe viewers to modern web maps shouldn't require complex GIS desktop software or uploading sensitive location data to third-party APIs.

A client-side converter provides a clean, fast way to transform Google Earth KML files into production-ready GeoJSON in seconds.

Give it a try for your next mapping project:

👉 Free Online KML to GeoJSON Converter

Feedback and feature suggestions are always welcome!

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.