# KML & KMZ viewer

> Open a KML or KMZ file, see it on a map and convert it to GeoJSON or CSV. Free, and no account needed.

Open the tool: https://spatibase.com/tools/kml-viewer/

The Spatibase KML & KMZ viewer opens KML and KMZ files in your web browser, shows their places, lines and areas on a map, and converts them to GeoJSON and CSV, and a KMZ to the KML inside it. It’s free with no account and no sign-up, and your file is read on your computer, never uploaded.

What to expect from the file:

- **Kept.** Names, descriptions, folders and extra data (`ExtendedData`).
- **Skipped, and counted.** Photos, icons and image overlays are left out, and the viewer says how many. Network links (data online) are not fetched.
- **Limit.** Files up to 50 MB.

## What it does
- Open KML and KMZ files (Google Earth, Google My Maps)
- Map preview of points, lines and areas
- List of every feature with its folder
- Convert KML to GeoJSON
- Convert KML to CSV with latitude, longitude and WKT
- Extract the KML from a KMZ
- Runs in the browser: nothing is uploaded

## How to open a KMZ or KML file
1. Export your map as KML or KMZ. In Google My Maps: the three-dot menu → Export to KML/KMZ. In Google Earth: right-click a folder → Save Place As.
2. Drop the file on the box above, or press Choose a file. No file at hand? Open a sample, or download the sample file to open it in Google Earth too.
3. Look at the map. Click a place to see its name and description.
4. Check the list under the map. Click a row to jump to that feature.
5. Download it as GeoJSON or CSV, or copy the GeoJSON. For a KMZ you can also download the KML inside it.

## Formats and limits
- **Opens:** .kml and .kmz, up to 50 MB.
- **Outputs:** GeoJSON (FeatureCollection), CSV (name, description, folder, every field, latitude/longitude for points, wkt for every shape), and the KML inside a KMZ.
- **Kept:** names, descriptions (as plain text), folders, ExtendedData fields.
- **Skipped:** photos, icons, image overlays (GroundOverlay, ScreenOverlay, PhotoOverlay) and network links (data online is not fetched).
- Try it with a sample: https://spatibase.com/tools/kml-viewer/?sample=1
- Download the sample file (the one Open a sample opens): https://spatibase.com/tools/samples/barcelona.kml

## KML vs KMZ: what is the difference?
The difference is the packaging:

- **KML is plain text.** A `.kml` file is XML that lists places, lines and areas with their names, descriptions and styles. Google Earth made the format popular, and Google My Maps exports it too.
- **KMZ is a zipped KML.** A `.kmz` holds the KML (usually `doc.kml`) and sometimes the photos, icons and image overlays it uses. To convert KMZ to KML, the viewer unzips it and gives you the KML inside, unchanged.

**What the viewer shows.** The places, lines and areas in the KML itself. Icons, photos and image overlays (`GroundOverlay`) are skipped, and it tells you how many.

## Convert KML to GeoJSON in JavaScript
The viewer uses two small open-source libraries: @tmcw/togeojson reads KML, and fflate unzips KMZ. These lines do the same job in your own code, in a browser.

```js
import { kml } from '@tmcw/togeojson'
import { unzipSync, strFromU8 } from 'fflate'

// file: a File from <input type="file">
const bytes = new Uint8Array(await file.arrayBuffer())
let text = strFromU8(bytes)
if (bytes[0] === 0x50 && bytes[1] === 0x4b) { // "PK": a KMZ is a zip
  const files = unzipSync(bytes, { filter: (f) => f.name.endsWith('.kml') })
  text = strFromU8(files['doc.kml'] ?? Object.values(files)[0])
}
const geojson = kml(new DOMParser().parseFromString(text, 'text/xml'))
```

**In Node.js.** There is no `DOMParser`: pass the text to the one from `@xmldom/xmldom` instead.

## Frequently asked questions
### Is my file uploaded?
No. The file is read by your browser, on your computer. Nothing is sent to Spatibase or anyone else. Only the map background (the streets and labels) is loaded from the internet.

### What is a KMZ file?
A KMZ is a zipped KML file. It contains the KML (often doc.kml) and sometimes the photos and icons it uses. The viewer opens it directly, and Download KML gives you the KML inside.

### Why don’t I see my photos, icons or image overlays?
The viewer shows the places, lines and areas in the file, with their text. Photos, custom icons and image overlays (GroundOverlay) are skipped, and the viewer says how many it skipped. Network links, which point to data online, are not fetched.

### Can I convert KML to GeoJSON or CSV?
Yes. After you open a file, Download GeoJSON gives you a GeoJSON FeatureCollection and Download CSV a table with one row per feature: name, description, folder, every other field, latitude and longitude for points, and the shape as WKT. Descriptions come out as plain text.

### Does it work with Google My Maps and Google Earth files?
Yes. Export from Google My Maps (Export to KML/KMZ) or save from Google Earth (Save Place As), then open the file here. Folders and layers become a folder column.

### Is there a size limit?
Yes, 50 MB per file. Very big files can still be slow, because everything runs on your computer. The list under the map shows the first 500 features, and the downloads include all of them.

## Next step
Turn the file into a live map your team can edit: **Save to Spatibase (free)** on the page saves it to a free Spatibase project (https://app.spatibase.com/signup), your places on a map you can edit and a live GeoJSON address for your site. Or download the GeoJSON and import it by hand (https://spatibase.com/docs/content/import/).
