I have a html file with a Google Map view embedded, and I’m using JavaScript to load a separate kml file’s data into the Google Map. In the KML file, I have the latitude/longitude coordinates of a car’s route, and I’ve used the LineString function to connect the coordinates into a single line. I’m wondering how to now animate a placemark on the LineString drawn by my given coordinates.
I’ve looked at this example, and it’s sort of what I’m trying to do, but the example doesn’t use a KML file. This example will animate a route given by latitude and longitude coordinates, but the command gx:track is only supported by Google Earth, and not Google Maps, according to my own testing and this thread.
Essentially, I’m trying to animate a placemark through predetermined coordinates on a web-based Google Maps interface. Here’s some of my code:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="2.2.xsd">
<Document>
<Placemark id="car">
<name>Initial position of car</name>
<description>Latitude: 31.2844 Longitude: 121.436</description>
<Point>
<coordinates>121.436,31.2844</coordinates>
</Point>
</Placemark>
<Placemark><LineString><coordinates>
121.436,31.2844,0
121.435,31.2857,0
121.435,31.2863,0
...more coordinates here...
</coordinates></LineString></Placemark>
</Document>
</kml>
How would I move the placemark with id of “car” along the linestring?
You can load your placemarks / lines from KML but in google maps you cannot define an animation (like a tour). To accomplish what you are asking you have to manipulate the map using the JavaScript API based on the contents of your KML file. That is – the example you posted is a great start point.
Also – I am working on something similar to this now (will be part of a deliverable due sometime over the next month – two). If you beat me to completing it you should post back with any lessons learned.