-2

Possible Duplicate:
Android - Get Altitude By Longitude and Latitude?

I require altitude for particular location from latitude and longitude.Any help would be highly appreciated.

Community
  • 1
  • 1
Pravin Divraniya
  • 4,223
  • 2
  • 32
  • 49
  • 1
    See the similar question http://stackoverflow.com/questions/1995998/android-get-altitude-by-longitude-and-latitude?rq=1 – whlk Jan 10 '13 at 10:26
  • 1
    http://developer.android.com/reference/android/location/Location.html see this.. – QuokMoon Jan 10 '13 at 10:30

2 Answers2

2

I have tried the Below Way in my application for getting Altitude from Lat/Long. you can try it out if it helps you.

private double getAltitudeFromLatLong(Double lat, Double long) {
    double result = 0.0;
    HttpClient httpClient = new DefaultHttpClient();
    HttpContext Context = new BasicHttpContext();
    String URL = "http://gisdata.usgs.gov/"
            + "xmlwebservices2/elevation_service.asmx/"
            + "getElevation?X_Value=" + String.valueOf(long)
            + "&Y_Value=" + String.valueOf(lat)
            + "&Elevation_Units=METERS&Source_Layer=-1&Elevation_Only=true";
    HttpGet httpGet = new HttpGet(URL);
    try {
        HttpResponse response = httpClient.execute(httpGet, Context);
        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 tag1 = "<double>";
            String tag2 = "</double>";
            if (respStr.indexOf(tag1) != -1) {
                int start = respStr.indexOf(tag1) + tag1.length();
                int end = respStr.indexOf(tag2);
                String value = respStr.substring(start, end);
                result = Double.parseDouble(value);
            }
            instream.close();
        }
    } 
    catch (Exception e) {}
    return result;
}
Bhavesh Patadiya
  • 25,740
  • 15
  • 81
  • 107
0

If u are using android device which has GPS Recever then there is a method getAltitude() by using that u can get the altitude by elevation.you can see this answer

Thanks

Community
  • 1
  • 1
Furqi
  • 2,403
  • 1
  • 26
  • 32