android - Google Maps Elevation Api 值错误

标签 android google-maps-api-3 elevation

我试过这种方法来获取海拔高度,使用经度和纬度

private double lookingForAltitude(double latitude, double longitude) {
        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(longitude)
                + "," + String.valueOf(latitude)
                + "&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;
                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));
                }
                instream.close();
            }
        } catch (ClientProtocolException e) {} 
        catch (IOException e) {}

        return result;
    }

不幸的是不起作用

例如通过

double latitude = 48.856908
double longitude = 2.352426

Rue de Tivoli Paris France

获取-3997.6191406

怎么了??

我在其他地方也得到了错误的值(value)。

附言

听说这个功能的请求上限是2500。 这与每个 IP 相关,还是所有使用我的证书的应用程序的最大数量?

最佳答案

您正在交换纬度和经度的值。

http://maps.googleapis.com/maps/api/elevation/xml?locations=2.352426,48.856908&sensor=true 返回:

<result>
<location>
<lat>2.3524260</lat>
<lng>48.8569080</lng>
</location>
<elevation>-3997.6191406</elevation>
<resolution>610.8129272</resolution>
</result>

http://maps.googleapis.com/maps/api/elevation/xml?locations=48.856908,2.352426&sensor=true 返回时:

<result>
<location>
<lat>48.8569080</lat>
<lng>2.3524260</lng>
</location>
<elevation>32.0345688</elevation>
<resolution>9.5439520</resolution>
</result>

您必须调用 lookingForAltitude 并交换值。

关于android - Google Maps Elevation Api 值错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13019319/

相关文章:

android - 为什么 ARCore 不支持 Nexus 9?

javascript - 使用 JavaScript 禁用缩放谷歌地图?

Flutter:ClipOval Clipper 高度

javascript - angularJS:谷歌地图未加载地点API

windows - 如何为 Windows 安装程序创建 list ?

c# - UAC or Userlevel 怎么克服呢!

java - Android 中自动取消通知

android - 为什么我们在 android 中每个类使用单个适配器?

android - 在屏幕上居中 LinearLayout,它本身包含布局

php - 谷歌地图信息窗口通过XML的多个地址