使用地图海拔 API
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. My request is :
My request
The result returned by the API is queried with the below code :
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 : 㰿硭氠症牳楯渽∱⸰∠敮捯摩涌㴢啔䘭㠢㼾਼䕬敶慑楯湒敳灯湳放ਠ㱳瑡瑵猾佋㰯獴慑畳㸊‼牥猎汴㸊†㱬潣慑楯浑ਠ†㱬慑㸴㔮㠱ㄲ㠰㜼⽬慑㸊†‼汮朾㌮〱㠴㘹㔼⽬涌㸊†㰯汯捡莹潮㸊†㱥汥痴莹潮㸸〳⸶㌶㜱㠸㰯敬敶慑楯浑ਠ‼牥獯汵莹潮㸱㤮〸㜹〴〼⽲敳潬畴楯浑ਠ㰯牥猎汴㸊㰯䕬敶慑楯湒敳灯湳放�
If I launch my request directly from my web browser, the result is correctly written in english, as it used to be...
Does anyone know how I can get an understandable answer in my app?
答案以 UTF-8 格式提供,但您试图将其解释为 UTF-16。
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. My request is : My request
The result returned by the API is queried with the below code :
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 : 㰿硭氠症牳楯渽∱⸰∠敮捯摩涌㴢啔䘭㠢㼾਼䕬敶慑楯湒敳灯湳放ਠ㱳瑡瑵猾佋㰯獴慑畳㸊‼牥猎汴㸊†㱬潣慑楯浑ਠ†㱬慑㸴㔮㠱ㄲ㠰㜼⽬慑㸊†‼汮朾㌮〱㠴㘹㔼⽬涌㸊†㰯汯捡莹潮㸊†㱥汥痴莹潮㸸〳⸶㌶㜱㠸㰯敬敶慑楯浑ਠ‼牥獯汵莹潮㸱㤮〸㜹〴〼⽲敳潬畴楯浑ਠ㰯牥猎汴㸊㰯䕬敶慑楯湒敳灯湳放�
If I launch my request directly from my web browser, the result is correctly written in english, as it used to be...
Does anyone know how I can get an understandable answer in my app?
答案以 UTF-8 格式提供,但您试图将其解释为 UTF-16。