我无法从反向地理编码的URL JSON响应中获得结果。 我也收到错误:
“ W / System.err:org.json.JSONException:输入结束处为字符“
这里是网址https://nominatim.openstreetmap.org/reverse?format=geojson&lat=14.6458&lon=121.0949
HttpDataHandler.java
public String GetHTTPData(String requestUrl)
{
URL url;
String response = "";
try{
url = new URL(requestUrl);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setReadTimeout(15000);
conn.setConnectTimeout(15000);
conn.setRequestMethod("GET");
conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
conn.setDoOutput(true);
int responseCode = conn.getResponseCode();
if(responseCode == HttpURLConnection.HTTP_OK)
{
String line;
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while((line = br.readLine()) != null)
response+=line;
}
else
response = "";
MainActivity
@Override
protected String doInBackground(String... strings) {
try{
double lat = Double.parseDouble(strings[0].split(",")[0]);
double lng = Double.parseDouble(strings[0].split(",")[1]);
String response;
HttpDataHandler http = new HttpDataHandler();
//String url = String.format("http://open.mapquestapi.com/geocoding/v1/reverse?key=2KtQuwfGGdfHxj6ybdgqcC7uFHrgVoJy&location=%.4f,%.4f",lat,lng);
String url = String.format("https://nominatim.openstreetmap.org/reverse?format=json&lat=%.4f&lon=%.4f",lat,lng);
response = http.GetHTTPData(url);
Log.d("testpandebug,doinbg", response);
Log.d("testpandebug,doinbg", url);
return response;
}
catch (Exception ex)
{
}
return null;
}
我正在使用日志从URL获取响应。使用其他地理编码器URL(带注释的字符串URL)后,它会返回响应,但是使用nominatim不会返回响应。我想使用nominatim,因为它会返回更准确的反向地址代码。