-2

可能重复:
Android - 通过经度和纬度获取高度?

我需要特定位置的纬度和经度高度。任何帮助将不胜感激。

4

2 回答 2

2

我在我的应用程序中尝试了以下方式从纬度/经度获取高度。如果对您有帮助,您可以尝试一下。

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;
}
于 2013-01-10T10:29:06.510 回答
0

如果您使用的是具有 GPS 接收器的 android 设备,那么有一个方法 getAltitude() 通过使用您可以通过海拔获取高度。您可以看到这个答案

谢谢

于 2013-01-10T10:27:52.437 回答