How to Display Custom KML Placemark Icon using Image from Local Disk or Network Drive

honor picture honor · Jun 19, 2014 · Viewed 20.4k times · Source

Does anybody know how to display custom KML Placemark icon using image from local disk or network drive.

I tried this and it is not working:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Style id="icon">
        <IconStyle>
          <Icon>
            <href>c:\etnasss.jpg</href>
          </Icon>
        </IconStyle>
 </Style>
  <Placemark>
    <name>Simple placemark</name>
    <description>Attached to the ground. Intelligently places itself 
       at the height of the underlying terrain.</description>
    <styleUrl>#icon</styleUrl>    
    <Point>
      <coordinates>-122.0822035425683,37.42228990140251,0</coordinates>
    </Point>
  </Placemark>
</kml>

Thanks

Answer

JasonM1 picture JasonM1 · Jun 20, 2014

The <href> element in KML takes a URL not a Windows file path. The URL can be an absolute or relative location.

To get it working, suggest you first move the KML file and the image to the same folder then refer to the image by its filename.

<Style id="icon">
    <IconStyle>
        <Icon>
          <href>etnasss.jpg</href>
        </Icon>
    </IconStyle>
</Style>

Source: https://developers.google.com/kml/documentation/kmlreference#href

Next, you could refer to the image by its absolute location (e.g. file:///C:/etnasss.jpg) but Google Earth has security policy regarding access to local files on the file system outside the context of the KML file. You'd have to allow access to local files which generally is not recommended.

Alternatively, you could create a KMZ file (aka ZIP file) and include the image within the KMZ archive file and reference it in the KML file.