How to display a moving boat in Google Earth?

e-satis picture e-satis · Oct 28, 2009 · Viewed 16.2k times · Source

I am new to the KML format and try to figure out how to display a boat (a png), moving from a place to another along a path (a simple line drawn composed of several lines).

I can see how to display a Placemark, even with an icon, and a Path, separately.

What I would like to see when I click on the KML file is :

  • the boat appearing at the departure point;
  • the path drawing itself until the arrival;
  • the boat icon moving at a comfortable speed (bonus point it I can set a ration time / progress, extra bonus if I can click on start, pause or rewind) from departure to arrival along the path.

Is that even possible ? I know it is with Google Map, but you can program it with Javascript, which eases things a lot.

Answer

gibbss picture gibbss · Nov 4, 2009

The only way I've been able to make this work in static KML is to interpolate between the start and stop points and add placemarks for each frame I want to animate. So, from t=0 to t=1, draw a placemark at the start point. From t=1 to t=2, draw a placemark at the next point, etc.

This gives you the temporal player bar in Google Earth and you can rewind or advance the animation. However it is a little annoying because you wind up with every interpolation point in your placemark tree. Putting the placemarks in their own folder keeps them out of the way, but there's no way to hide them from the user.

Take a look at http://code.google.com/apis/kml/documentation/time.html#animating The whale shark example does more or less what you want for the placemark. (The URL for the marker icon is broken). Animating the progress along the track can be done using the same trick.

If you want to try something much more difficult, you can try serving dynamic KML. Have Google Earth load a network link to your initial data. Then load another network link with an that sends an update for your placemark at every time tick.

This approach has some serious disadvantages because it requires an external program to drive Google Earth and it does not give the user access to the built-in Google Earth temporal player bar. It also requires that all the data be loaded over a network link -- KML data from a file cannot be updated. That means your driver program needs to act as a http server. Also, in this model it is very hard to know exactly when Google Earth has finished loading and drawing the update. Really I don't recommend doing this; you can make it work using the Google Earth COM API, but it will always be a fragile solution.