You can also use the Google Elevation API. The online documentation for it is located at:
https://developers.google.com/maps/documentation/elevation/
Please note the following from the above API page:
Usage Limits: Use of the Google
Geocoding API is subject to a query
limit of 2,500 geolocation requests
per day. (User of Google Maps API
Premier may perform up to 100,000
requests per day.) This limit is
enforced to prevent abuse and/or
repurposing of the Geocoding API, and
this limit may be changed in the
future without notice. Additionally,
we enforce a request rate limit to
prevent abuse of the service. If you
exceed the 24-hour limit or otherwise
abuse the service, the Geocoding API
may stop working for you temporarily.
If you continue to exceed this limit,
your access to the Geocoding API may
be blocked. Note: the Geocoding API
may only be used in conjunction with a
Google map; geocoding results without
displaying them on a map is
prohibited. For complete details on
allowed usage, consult the Maps API
Terms of Service License Restrictions.
Altering Max Gontar s code above for the Google API gives the following, with the returned elevation given in feet:
private double getElevationFromGoogleMaps(double longitude, double latitude) {
double result = Double.NaN;
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
String url = "http://maps.googleapis.com/maps/api/elevation/"
+ "xml?locations=" + String.valueOf(latitude)
+ "," + String.valueOf(longitude)
+ "&sensor=true";
HttpGet httpGet = new HttpGet(url);
try {
HttpResponse response = httpClient.execute(httpGet, localContext);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
int r = -1;
StringBuffer respStr = new StringBuffer();
while ((r = instream.read()) != -1)
respStr.append((char) r);
String tagOpen = "<elevation>";
String tagClose = "</elevation>";
if (respStr.indexOf(tagOpen) != -1) {
int start = respStr.indexOf(tagOpen) + tagOpen.length();
int end = respStr.indexOf(tagClose);
String value = respStr.substring(start, end);
result = (double)(Double.parseDouble(value)*3.2808399); // convert from meters to feet
}
instream.close();
}
} catch (ClientProtocolException e) {}
catch (IOException e) {}
return result;
}