How should a program determine that the Google Earth API has fetched an accurate altitude for a location?
The Google Earth Plugin API has the following method to get ground altitude:
double GEGlobe.getGroundAltitude(double lat, double lon)
However, this function returns different results depending on the camera's distance from the targeted latitude, longitude. For example if the true altitude for a location is: +181.60
Calling the function when the camera is at different distances from the location returns the following altitudes:
Return values of getGroundAltitude at different camera positions:
-19.38 (camera is very far from location)
+06.11 (camera is now closer)
+89.13 (...)
+166.82
+177.47
+181.53 (camera is now v.close to the location)
The returned value 181.53 is close enough to true altitude of 181.60
The question is, how should the program determine that it has reliably got the most accurate altitude?
This is one of the pitfalls of Google Earth. The ground altitude thing depends on the quality of imagery that is available for that given point. So, it the imagery is good, the value will be accurate, if the imagery is bad the value could be bad.
You can check how much imagery is loaded with getStreamingPercent()
-- the ground altitude value should get more accurate as the streaming percent increases.
You may want to use Google's elevation API, which actually calls out to get the data from an external server (where the % loaded doesn't come into play.) The downside to this method is that it requires internet connectivity, so that's something to keep in mind.
https://developers.google.com/maps/documentation/elevation/
Edit
Another thing to remember, that getGroundAltitude()
call is very finicky. It's trying to get the value for a single point on the Earth -- but it doesn't have very good error checking (ie. it might not know the value for point X,Y, so it returns something wrong even though all points surrounding X,Y have valid data.)