[英]Using Maps Elevation API
In my app, when I try to get an elevation with the "Maps Elevation API", I get an answer which looks like a Chinese answer.在我的应用程序中,当我尝试使用“Maps Elevation API”获取海拔高度时,我得到一个看起来像中文答案的答案。 My request is: My request我的要求是: 我的要求
The result returned by the API is queried with the below code:查询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éponse
variable looks like this: 㰿硭氠癥牳楯渽∱⸰∠敮捯摩湧㴢啔䘭㠢㼾਼䕬敶慴楯湒敳灯湳放ਠ㱳瑡瑵猾佋㰯獴慴畳㸊‼牥獵汴㸊†㱬潣慴楯渾ਠ†㱬慴㸴㔮㠱ㄲ㠰㜼⽬慴㸊†‼汮朾㌮〱㠴㘹㔼⽬湧㸊†㰯汯捡瑩潮㸊†㱥汥癡瑩潮㸸〳⸶㌶㜱㠸㰯敬敶慴楯渾ਠ‼牥獯汵瑩潮㸱㤮〸㜹〴〼⽲敳潬畴楯渾ਠ㰯牥獵汴㸊㰯䕬敶慴楯湒敳灯湳放� 现在,我在我的ligneRéponse
变量中得到的内容如下所示:㰿硭氠症牳楯渽∱⸰∠敮捯摩涌㴢啔䘭㠢㼾਼䕬敶预防楯湒敳湳ਠ㱳瑡瑵逼佋㰲獴猎畳㸊‼牥汴㸊†㱬潥预防楯ਠ†㱬预防㸴㔮㠱ㄲ㠰㜼⽬预防㸮痴†‼汮朾㌮〱㠴㘹㔼⽬涌㸊†㰯汱莹潮㸊†㱥㱥潮㸸〳⸶㌶㜱㠸㰯敬敶预防楯ਠ‼牥獯汵潮㸱㤮〸㜹〴〼⽲敳潬放浑莹楯ਠ㰯牥莹莹猎湴灯㸊㰯䕬敶灯楯敬敶湳楯敬
If I launch my request directly from my web browser, the result is correctly written in english, as it used to be...如果我直接从我的 web 浏览器启动我的请求,结果会正确地用英文书写,就像以前一样......
Does anyone know how I can get an understandable answer in my app?有谁知道我如何在我的应用程序中获得可以理解的答案?
The answer comes in UTF-8, but you are trying to interpret it as UTF-16.答案来自 UTF-8,但您试图将其解释为 UTF-16。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.