使用Maps Elevation API

Zelig63:

在我的应用中,当我尝试使用“ Maps Elevation API”获取高程时,得到的答案看起来像中文答案。我的要求是:我的要求

使用以下代码查询API返回的结果:

            try {
            url = new URL(arg0[0]);
            urlConnection = (HttpURLConnection)url.openConnection();
            try {
                urlConnection.setRequestMethod("POST");
                urlConnection.setDoInput(true);
                urlConnection.setDoOutput(true);
                os=urlConnection.getOutputStream();
                bw=new BufferedWriter(new OutputStreamWriter(os,"UTF_16"));
                bw.flush();
                bw.close();
                is = urlConnection.getInputStream();
                br = new BufferedReader(new InputStreamReader(is, "UTF_16"));
                while ((ligneRéponse = br.readLine()) != null) {
                    if(ligneRéponse.length()!=0) {e
                        if (ligneRéponse.contains("<elevation>")) {
                            if (ligneRéponse.contains("<elevation>")) {
                                altitude = Double.parseDouble(ligneRéponse.substring(ligneRéponse.indexOf("<elevation>") + 11, ligneRéponse.indexOf("</elevation>")));
                            } else {
                                altitude = -10000;
                            }
                        }
                    }
                }
                is.close();
            } finally {
                urlConnection.disconnect();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        return(altitude);

Until recently, this code was working perfectly. Now, what I get in my ligneRéponsevariable looks like this :㰿硭氠症牳楯渽∱⸰∠敮捯摩涌㴢啔䘭㠢㼾਼䕬敶慑楯湒敳灯湳放ਠ㱳瑡瑵猾佋㰯獴慑畳㸊‼ 牥猎汴㸊†㱬潣慑楯浑ਠ†㱬慑㸴㔮㠱ㄲ㠰㜼⽬慑㸊†‼ 汮朾㌮ 〱㠴㘹㔼⽬涌㸊†㰯汯捡莹潮㸊†㱥汥痴莹潮㸸〳 ⸶㌶㜱㠸㰯敬敶慑楯浑ਠ‼ 牥獯汵莹潮㸱㤮〸㜹〴 〼 ⽲敳潬畴楯浑ਠ㰯牥猎汴㸊㰯䕬敶慑楯湒敳灯湳放

如果我直接从Web浏览器启动请求,结果将正确地用英语书写,因为它以前是...

有谁知道我如何在我的应用程序中得到一个可以理解的答案?

mentallurg:

答案来自UTF-8,但是您试图将其解释为UTF-16。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章