1

I need to develop app to calculate elevation building ,,, i use this code but it calculate elevation ground from sea floor

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
            //    result = (double)(Double.parseDouble(value));
            }
            instream.close();
        }
    } catch (ClientProtocolException e) {} 
    catch (IOException e) {}

    return result;
}

Can any one help me how to calculate elevation building from ground ... ??

1 Answers1

0

Google and other such services only can provide you with a height above sea-level. If you want to calculate the height of the building you'd have to use a device with a barometer sensor, which measures the atmospheric pressure. See http://developer.android.com/reference/android/hardware/SensorEvent.html and Sensor.TYPE_PRESSURE. I'm not aware of devices actually having such a sensor though... Alternatively you could use an altimeter or perhaps look up the building's plan (if it's a specific building).

Ridcully
  • 23,362
  • 7
  • 71
  • 86
  • http://stackoverflow.com/questions/7410095/android-is-there-a-way-to-obtain-altitude-aside-from-location-getaltitude-i?rq=1 I use this code for sensor but Sensor Manger Method not working,, and application go standby mode .. :( – Moath Fararjeh Aug 29 '12 at 15:12