我无法从反向地理编码的 URL JSON 响应中获取结果。我也收到错误:
“W/System.err: org.json.JSONException: 在字符 0 处的输入结束”
这是网址 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 = "";
主要活动
@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,因为它返回更准确的反向地理编码。
哆啦的时光机
相关分类