When creating the Santa Tracker we made use of some code we had previously written for creating arcs in Google Earth. As we noted in that post, however, the arcs use relative altitudes, but for smaller arcs there can be noticeable dips and bumps in line with the underlying terrain. The other alternative is to use absolute altitudes but this results in arcs that end at a fixed altitude either underground or up in the sky, depending on the altitude one sets and the altitude of the ground at the ends of each arc. Neither of these possibilities was satisfactory for the Santa Tracker as it often shows the arcs up close and Santa himself is shown following the arc and would bounce around alarmingly as he flies over mountains and rivers below.
The cause of the problem is simple. KML paths and polygons that are drawn in KML do not have any altitudes associated with each point. It is possible to set the whole path or polygon to either follow the terrain or be at a specific altitude, but you cannot adjust the altitude of individual points. KML does, however, support altitudes and KMLs derived from other sources, such as GPS’s, which include altitude, do correctly display the altitudes in Google Earth, and we actually used this feature when creating the arcs mentioned above.
To draw nice smooth arcs that end at ground level at each end we need to know what the absolute altitude of ground level is for each end of the arc – but this is not available in the KML file. So we did some investigation and discovered that Google provides an elevation API as part of the Google Maps API. So, to create our arcs we first obtain the altitudes of all the points along the path or polygon and then we can draw nice looking arcs and give Santa a smooth ride.
We also thought that maybe other people might find a use for code that takes a KML of a path or polygon and adds in the altitude data from the Google Maps Elevation API. So, here it is:
Simply select a KML containing paths or polygons and the script will add altitude data from the Google Maps Elevation Service. You probably won’t see any difference in the resulting KML file when loaded in Google Earth, as the paths or polygons will still be at ground level. However, if you check the properties of a path or polygon you will see that it now shows various altitudes instead of an altitude of zero. Its real use is in cases where you want to do further processing, as we did for creating arcs. If anyone finds this useful do let us know in the comments what application you found it useful for.
Note that the Elevation Service is not intended to be used to extract large quantities of elevation data, so don’t expect to be able to use it to copy whole areas of elevation information into other applications.