Search code examples
iconskmlkmz

How can I reference local custom icons in a kml?


I have quite literally never tried to edit a kml file before, so I'm not totally sure of what I'm trying to ask, but I'll do my best.

I'm trying to use custom icons for my placemarkers. I tried to upload the images to a hosting site and link to them, and I also tried putting them into a subfolder and referencing the local address. Here are those attempts.

  <Style id="1">
    <IconStyle>
      <Icon>
    <href>https://cdn1.imggmi.com/uploads/2019/3/8/63626b5bc964d76ca0d5bdb30fb44afd-full.png</href>
      </Icon>
    </IconStyle>
    </Style>

And the second method:

  <Style id="1">
    <IconStyle>
      <Icon>
        <href>files/number_1.png</href>
      </Icon>
    </IconStyle>
    </Style>

And the placemarker references the style like this:

        <Placemark>
            <styleUrl>#1</styleUrl>
            <Point>
                <coordinates>-86.78824404543640,36.41901416833124,1005.84</coordinates>
                <altitudeMode>absolute</altitudeMode>
            </Point>
        </Placemark>

No matter what I do, I can't get the icon to show up in GE. I have read a bunch of different tutorials, tried naming the folder and subfolder differently, and tried making a kmz with the kml in the main folder and the icons in a subfolder. Nothing seems to work. It feels like I'm missing something basic or fundamentally misunderstanding some aspect of this, but for the life of me I can't seem to figure it out!

Any help is appreciated!


Solution

  • This KML works for me in Google Earth in a KMZ/zip file:

    <?xml version="1.0" encoding="utf-8"?>
    <kml xmlns="http://www.opengis.net/kml/2.2">
      <Document>
      <Style id="1">
        <IconStyle>
          <Icon>
            <href>files/number_1.png</href>
          </Icon>
        </IconStyle>
        </Style>
        <Placemark>
          <styleUrl>#1</styleUrl>
          <Point>
              <coordinates>-86.78824404543640,36.41901416833124,1005.84</coordinates>
              <altitudeMode>absolute</altitudeMode>
          </Point>
        </Placemark>
      </Document>
    </kml>
    

    The file number_1.png is in the "files" directory. KMZ file contents

    displayed on Google Maps

    on Google Earth: displayed on Google Earth