需要经度和纬度的高度

时间:2013-01-10 10:21:49

标签: android

  

可能重复:
  Android - Get Altitude By Longitude and Latitude?

我要求从纬度和经度的特定位置的高度。任何帮助将非常感激。

2 个答案:

答案 0 :(得分:2)

我在我的应用程序中尝试了以下方式从Lat / Long获取海拔高度。你可以尝试一下,如果它可以帮助你。

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

答案 1 :(得分:0)

如果您正在使用具有GPS Recever的Android设备,那么有一个方法getAltitude()使用你可以通过海拔获得高度。你可以看到这个answer

谢谢