Back to Blog
Technical
January 8, 20247 min read

How to Create a KML File for Google Maps

KML files store geographic data that Google My Maps can import. This walkthrough covers KML structure, coordinate formatting, pin descriptions, and tools that generate these files for local SEO campaigns.

StackMyMap Team

Local SEO Expert

How to Create a KML File for Google Maps

KML stands for Keyhole Markup Language, an XML-based format originally created for Google Earth. Google My Maps accepts KML files for importing locations, pins, and routes. For map stacking campaigns, KML files let you create consistent, error-free maps at scale.

KML File Structure

A KML file follows standard XML formatting. The basic structure includes:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
    <name>Your Map Title</name>
    <description>Map description text</description>
    
    <Placemark>
      <name>Pin Title</name>
      <description>Pin description with NAP</description>
      <Point>
        <coordinates>-87.6298,41.8781,0</coordinates>
      </Point>
    </Placemark>
    
  </Document>
</kml>

Coordinate Formatting

KML uses longitude-latitude-altitude format, not latitude-longitude. This catches many people:

  • Correct: -87.6298,41.8781,0 (longitude, latitude, altitude)
  • Incorrect: 41.8781,-87.6298,0 (latitude, longitude, altitude)

The altitude value (the third number) is typically 0 for ground-level locations. Include no spaces between the comma-separated values.

Finding Coordinates

Get coordinates for any address using Google Maps:

  1. Open Google Maps and search for your address
  2. Right-click on the exact location
  3. Click the coordinates that appear (they copy to your clipboard)
  4. Swap the order from lat,lng to lng,lat for your KML file

Adding Multiple Pins

Each pin requires its own Placemark block. A map with three pins looks like:

<Document>
  <name>Chicago Plumber Services</name>
  
  <Placemark>
    <name>ABC Plumbing - Main Office</name>
    <description>
      ABC Plumbing
      123 Main St, Chicago, IL 60601
      (312) 555-1234
      https://abcplumbing.com
    </description>
    <Point>
      <coordinates>-87.6298,41.8781,0</coordinates>
    </Point>
  </Placemark>
  
  <Placemark>
    <name>Service Area - Lincoln Park</name>
    <description>Serving Lincoln Park residents</description>
    <Point>
      <coordinates>-87.6500,41.9200,0</coordinates>
    </Point>
  </Placemark>
  
  <Placemark>
    <name>Service Area - Wicker Park</name>
    <description>Serving Wicker Park residents</description>
    <Point>
      <coordinates>-87.6770,41.9080,0</coordinates>
    </Point>
  </Placemark>
  
</Document>

Custom Pin Styles

KML supports custom pin colors and icons through Style definitions:

<Document>
  <Style id="bluePin">
    <IconStyle>
      <color>ffff0000</color>
      <scale>1.0</scale>
    </IconStyle>
  </Style>
  
  <Placemark>
    <styleUrl>#bluePin</styleUrl>
    <name>My Pin</name>
    ...
  </Placemark>
</Document>

Color codes use AABBGGRR format (alpha, blue, green, red), not the typical RGB hex codes. For example, ff0000ff creates a red pin.

Adding Links in Descriptions

Include clickable links in pin descriptions using HTML anchor tags:

<description><![CDATA[
  <p>ABC Plumbing - Emergency Services</p>
  <p>123 Main St, Chicago, IL 60601</p>
  <p>(312) 555-1234</p>
  <p><a href="https://abcplumbing.com">Visit Website</a></p>
  <p><a href="https://maps.google.com/?cid=12345">Google Business Profile</a></p>
]]></description>

The CDATA wrapper allows HTML within the description field. Without it, angle brackets break the XML structure.

Organizing with Folders

Group related pins using Folder elements:

<Document>
  <Folder>
    <name>Business Location</name>
    <Placemark>...</Placemark>
  </Folder>
  
  <Folder>
    <name>Service Areas</name>
    <Placemark>...</Placemark>
    <Placemark>...</Placemark>
  </Folder>
</Document>

Validating Your KML File

Before importing to Google My Maps, validate your KML file:

  • Open the file in a text editor and check for XML syntax errors
  • Verify all tags are properly closed
  • Check coordinate format (longitude first)
  • Test import in a scratch map before using production files

People Also Ask About KML Files

Can I convert other file formats to KML?

Yes. Google My Maps can import CSV, XLSX, and GPX files directly. For other formats, conversion tools exist online. CSV works well for bulk location data with columns for address, name, and description.

Is there a size limit for KML files?

Google My Maps limits imports to 2,000 rows and 5 MB file size. For map stacking, this is rarely an issue since individual maps typically contain 10-25 pins.

Why won't my KML file import?

Common import failures stem from: invalid XML syntax, incorrect coordinate formatting (lat/lng swapped), missing closing tags, or encoding issues. Open the file in a code editor to check for errors.

Should I create KML files manually or use a tool?

Manual creation works for single maps but becomes tedious for campaigns with multiple maps. KML generator tools automate coordinate lookup, proper formatting, and link embedding. StackMyMap generates optimized KML files from your business information.

Using StackMyMap for KML Generation

StackMyMap's KML generator handles the technical details automatically. Enter your business address, target keywords, and service area, and the tool produces properly formatted KML files ready for Google My Maps import.

The generated files include optimized pin placement, NAP-consistent descriptions, and links to your website and Google Business Profile.

Ready to Start Map Stacking?

Create your first map stack in minutes with StackMyMap's automated KML generator and Drive stack builder.

Get Started Free