1

我需要开发应用程序来计算海拔高度,我使用这个代码,但它从海底计算海拔高度

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;
}

任何人都可以帮助我如何从地面计算海拔高度......?

4

1 回答 1

0

谷歌等此类服务只能为您提供海拔高度。如果要计算建筑物的高度,则必须使用带有气压计传感器的设备,该设备可以测量大气压力。请参阅http://developer.android.com/reference/android/hardware/SensorEvent.htmlSensor.TYPE_PRESSURE. 我不知道实际上有这样一个传感器的设备......或者你可以使用高度计或者查看建筑物的计划(如果它是一个特定的建筑物)。

于 2012-08-29T12:11:44.183 回答