1

I have a KML file that I am trying to animate. I have changed the icon heading already in the KML code, but the custom icon still rotates.

<IconStyle>
            <heading>0</heading>
            <scale>3</scale>
            <Icon>
                <href>avatar.png</href>
            </Icon>
            <hotSpot x="0.5" y="0.5" xunits="fraction" yunits="fraction"/>
</IconStyle>

Is it possible I have to modify each placemark?

</description>
                    <LookAt>
                        <longitude>140.758037</longitude>
                        <latitude>41.798489</latitude>
                        <altitude>0</altitude>
                        <heading>0</heading>
                        <tilt>66</tilt>
                        <range>0.1</range>
                    </LookAt>
                    <TimeStamp><when>2021-09-05T04:30:52Z</when>
</TimeStamp>
                    <styleUrl>#multiTrack</styleUrl>
                    <Point>
                        <coordinates>140.758037,41.798489,19.83</coordinates>
                    </Point>
                </Placemark>
                <Placemark>
                    <name>Route 2021-09-05 12:43pm-508</name>
                    <snippet></snippet>
                    <description><![CDATA[<table>
<tr><td>Longitude: 140.758027 </td></tr>
<tr><td>Latitude: 41.798486 </td></tr>
<tr><td>Altitude: 19.858 meters </td></tr>
<tr><td>Heading: 0 </td></tr>
<tr><td>Time: 2021-09-05T04:30:53Z </td></tr>
</table>]]></description>

I have tried to play the KML file in Google Earth Pro.

My objective is to have the custom icon in the KML move along the path always oriented "0" north.

1 Answer 1

0

You should be able to apply the <heading> tag to your <IconStyle> (in a shared Style, or within each Placemark), and fix the direction an icon points relative to the compass direction. The heading is specified in degrees, with zero being north, 180 being south, etc.

If you do NOT specify a heading in the IconStyle (or don't have an IconStyle section at all), then the icon will use the default behavior and maintain its heading relative to your screen (eg: pointing up), even when you rotate the earth/map (eg: turn north down). Now it looks like there is a quirk in Earth Pro where if you specify a heading of "0" (zero), I would expect the icon to always point north, but instead it acts as if there is no heading specified, and the icon doesn't turn with the map. But any other number you specify for a heading seems to work and keeps the icon oriented. Additionally, 360 works, so to specify north use 360 instead of zero.

Below is an sample KML file which you can copy/paste into Earth Pro, to see examples of various heading settings. The two on the ends (heading not specified and heading = 0) both display the default behavior. But all the others show the icon maintaining its compass heading and rotating as you rotate the map (keyboard shortcut to rotate is Shift and Left-Arrow or Right-Arrow). Note that you can put the IconStyle and heading into inline Styles in each Placemark like I've done here for simplicity, or you can put them in a shared Style that is referenced by one or more Placemarks using a styleUrl tag.

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
<Document>
    <name>Icon heading test</name>
    <open>1</open>
    <Placemark>
        <name>heading 0 (north - broken, turns)</name>
        <Style>
            <IconStyle>
                <scale>2</scale>
                <Icon>
                    <href>http://maps.google.com/mapfiles/kml/shapes/track.png</href>
                </Icon>
                <hotSpot x="0.5" y="0.5" xunits="fraction" yunits="fraction"/>
                <heading>0</heading>
            </IconStyle>
        </Style>
        <Point>
            <coordinates>-136,36,0</coordinates>
        </Point>
    </Placemark>
    <Placemark>
        <name>heading 360(also north)</name>
        <Style>
            <IconStyle>
                <scale>2</scale>
                <Icon>
                    <href>http://maps.google.com/mapfiles/kml/shapes/track.png</href>
                </Icon>
                <hotSpot x="0.5" y="0.5" xunits="fraction" yunits="fraction"/>
                <heading>360</heading>
            </IconStyle>
        </Style>
        <Point>
            <coordinates>-137,36,0</coordinates>
        </Point>
    </Placemark>    
    <Placemark>
        <name>heading 1 (north +1)</name>
        <Style>
            <IconStyle>
                <scale>2</scale>
                <Icon>
                    <href>http://maps.google.com/mapfiles/kml/shapes/track.png</href>
                </Icon>
                <hotSpot x="0.5" y="0.5" xunits="fraction" yunits="fraction"/>
                <heading>1</heading>
            </IconStyle>
        </Style>
        <Point>
            <coordinates>-138,36,0</coordinates>
        </Point>
    </Placemark>
    <Placemark>
        <name>heading 90 (east)</name>
        <Style>
            <IconStyle>
                <scale>2</scale>
                <Icon>
                    <href>http://maps.google.com/mapfiles/kml/shapes/track.png</href>
                </Icon>
                <hotSpot x="0.5" y="0.5" xunits="fraction" yunits="fraction"/>
                <heading>90</heading>
            </IconStyle>
        </Style>
        <Point>
            <coordinates>-139,36,0</coordinates>
        </Point>
    </Placemark>
    <Placemark>
        <name>heading 180 (south)</name>
        <Style>
            <IconStyle>
                <scale>2</scale>
                <Icon>
                    <href>http://maps.google.com/mapfiles/kml/shapes/track.png</href>
                </Icon>
                <hotSpot x="0.5" y="0.5" xunits="fraction" yunits="fraction"/>
                <heading>180</heading>
            </IconStyle>
        </Style>
        <Point>
            <coordinates>-140,36,0</coordinates>
        </Point>
    </Placemark>
    <Placemark>
        <name>heading 270 (west)</name>
        <Style>
            <IconStyle>
                <scale>2</scale>
                <Icon>
                    <href>http://maps.google.com/mapfiles/kml/shapes/track.png</href>
                </Icon>
                <hotSpot x="0.5" y="0.5" xunits="fraction" yunits="fraction"/>
                <heading>270</heading>
            </IconStyle>
        </Style>
        <Point>
            <coordinates>-141,36,0</coordinates>
        </Point>
    </Placemark>
    <Placemark>
        <name>heading not specified (should spin)</name>
        <Style>
            <IconStyle>
                <scale>2</scale>
                <Icon>
                    <href>http://maps.google.com/mapfiles/kml/shapes/track.png</href>
                </Icon>
                <hotSpot x="0.5" y="0.5" xunits="fraction" yunits="fraction"/>
            </IconStyle>
        </Style>
        <Point>
            <coordinates>-142,36,0</coordinates>
        </Point>
    </Placemark>    
</Document>
</kml>
2
  • I was able to change the heading by adding it to the style, but when I play the path, the icon still rotates when moving along the path. Any other idea how to stop the icon rotating? Basically, when the path is heading west, the icon will turn 90 degrees to point the top of the icon to the right. If the path is a circle, the icon will rotate along the path 360 degrees. Jul 15 at 10:14
  • Can you provide some more specifics of what you mean by "play the path"? Are you using a line (aka path) and playing it back in the Movie Maker or Tour creator? Or do you have an animated KML Track generated from a GPS data file? Or something else. I ask because there is another heading control used in KML Tracks (the gx:angles tag). If you're able to share a sample KML file, that would make debugging much easier. Jul 16 at 20:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.