0
votes

I have a KML file created in ArcGIS 10.0 that will load in both Google Maps and Google Earth, but won't load using the Google Map javascript API. I get a message that it's an invalid KML file and unfortunately neither of the online KML validator tools are working right now.

I'm new to KML, any ideas what the issue could be? Here is my KML file structure:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2"><Document id="River Basin">
    <name>River Basin</name>
    <Snippet></Snippet>
    <Folder id="FeatureLayer0">
        <name>River Basin</name>
        <Snippet></Snippet>
        <Placemark id="ID_00000">
            <name>18010110</name>
            <Snippet></Snippet>      
            <styleUrl>#PolyStyle00</styleUrl>
            <MultiGeometry>
                <Polygon>
                    <extrude>0</extrude><altitudeMode>clampToGround</altitudeMode><tessellate>1</tessellate>
                    <outerBoundaryIs><LinearRing><coordinates> -300.1606990983578,50.39764575695928,etc</coordinates></LinearRing></outerBoundaryIs>
                </Polygon>
            </MultiGeometry>
         </Placemark>
    </Folder>
    <Style id="PolyStyle00">
        <LabelStyle>
            <color>00000000</color>
            <scale>0.000000</scale>
        </LabelStyle>
        <LineStyle>
            <color>ff0000ff</color>
            <width>2.000000</width>
        </LineStyle>
        <PolyStyle>
             <color>00f0f0f0</color>
             <outline>1</outline>
        </PolyStyle>
    </Style>
  </Document>
</kml>

Thank you,

Joy

2

2 Answers

2
votes

The structure of your KML is not valid. Google Maps API might have issues if it is not correct so first need to make it a valid KML file.

The correct structure of the Document in KML spec is

<Document id="ID">
  <!-- inherited from Feature element -->
  <name>...</name> 
  ...
  <Style>..</Style> or <styleUrl>...</styleUrl>

  <!-- specific to Document -->
  <!-- 0 or more Schema elements -->
  <!-- 0 or more Feature elements -->
</Document>

Try moving the <Style> element before the <Folder> element. That will make it a valid KML file.

Whenever you encounter a KML-related issue, it is recommended to first validate it using KML validator or Feed Validator. Fix KML errors first then address other errors.

0
votes

The suggestion to place the style element above the folder element worked - Thank you!

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2"><Document id="River Basin">
<name>River Basin</name>
<Snippet></Snippet>
<Style id="PolyStyle00">
    <LabelStyle>
        <color>00000000</color>
        <scale>0.000000</scale>
    </LabelStyle>
    <LineStyle>
        <color>ff0000ff</color>
        <width>2.000000</width>
    </LineStyle>
    <PolyStyle>
         <color>00f0f0f0</color>
         <outline>1</outline>
    </PolyStyle>
</Style>
<Folder id="FeatureLayer0">
    <name>River Basin</name>
    <Snippet></Snippet>
    <Placemark id="ID_00000">
        <name>18010110</name>
        <Snippet></Snippet>      
        <styleUrl>#PolyStyle00</styleUrl>
        <MultiGeometry>
            <Polygon>
                <extrude>0</extrude><altitudeMode>clampToGround</altitudeMode><tessellate>1</tessellate>
                <outerBoundaryIs><LinearRing><coordinates> -300.1606990983578,50.39764575695928,etc</coordinates></LinearRing></outerBoundaryIs>
            </Polygon>
        </MultiGeometry>
     </Placemark>
</Folder>    
</Document>
</kml>