Search code examples
htmlgoogle-maps-api-3kmlgoogle-earth

How to change the style of a marker from a KML file?


I am trying to change the style of a marker from a KML file in googlemaps. When I run the file in googleearth, the marker is different. When I run it in googlemaps it's just the same looking marker as before. Why is that happening?

Here's the beginning of the kml file:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.google.com/earth/kml/1">
<Document>

<Style id="bendigo">
<BalloonStyle>
    <text>$[description]</text>
</BalloonStyle>
<IconStyle>
    <Icon>
        <href>http://maps.google.com/mapfiles/kml/paddle/grn-blank.png</href>
    </Icon>
  </IconStyle>
</Style>

<name>kml_sample1.kml</name>
<Placemark>
 <name>Boat</name>
 <description><![CDATA[
  Boat<br />
  <p>Home page: <a href="google.com">google.com</a></p>
 ]]>
 </description>

 <styleUrl>#bendigo</styleUrl>

<Point>
<!--run a javascript to get data points-->
  <coordinates>7.666037,64.32565</coordinates>
</Point>


Solution

  • Your KML snippet above is missing ending tags for Placemark, Document, and kml.

    Once fixed I was able to load the KML into Google Maps and it looks fine (green marker).

    There was a recent update to the KML is rendered in Google Maps which may have temporarily affected this, but I am unable to be sure since it works fine for me now. If you confirm it now looks fine to you, that was probably the issue.