0

我使用此方法使用经度和纬度坐标检索高度

private double getAltitude(int long, int lat) {
    Double longitude=Double.valueOf((double)(long/1e6)); 
    Double latitude=Double.valueOf((double)(lat/1e6));
    double result = Double.NaN;
    HttpClient httpClient = new DefaultHttpClient();
    HttpContext localContext = new BasicHttpContext();
    String url = "http://gisdata.usgs.gov/"
            + "xmlwebservices2/elevation_service.asmx/"
            + "getElevation?X_Value=" + String.valueOf(longitude)
            + "&Y_Value=" + String.valueOf(latitude)
            + "&Elevation_Units=METERS&Source_Layer=-1&Elevation_Only=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 = "<double>";
            String tagClose = "</double>";
            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.parseDouble(value);
            }
            instream.close();
        }
    } catch (ClientProtocolException e) {} 
    catch (IOException e) {}
    return result;
}

这使用网络服务http://gisdata.usgs.gov/xmlwebservices2/elevation_service.asmx

传递的坐标是从谷歌地图获得的int

int long=(int)(map.getLong()*1e6);
int lat=(int)(map.getLatitude()*1e6);

参数格式出了点问题,因为使用这种方法我得到完全错误的高度或负值 -1,8398598E4..

我已经用法国某个地方的坐标进行了测试

44.783333 纬度10.516667 长

4

0 回答 0