无法从 nominatim url (openstreetmap) 得到 JSON
Can't get JSON from nominatim url (openstreetmap)
我无法从反向地理编码的 URL JSON 响应中获取结果。
我也收到错误:
"W/System.err: org.json.JSONException: End of input at character 0 of "
这里是urlhttps://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)时,它 return 是一个响应,但是,使用 nominatim 不会 return 响应。我想使用 nominatim,因为它 return 是一种更准确的反向地理编码。
如果它 return 不是有效的 body,则查看 HTTP 响应 header。我猜你违反了 Nominatim's usage policy。您提供有效的 HTTP 用户代理吗?
我无法从反向地理编码的 URL JSON 响应中获取结果。 我也收到错误:
"W/System.err: org.json.JSONException: End of input at character 0 of "
这里是urlhttps://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)时,它 return 是一个响应,但是,使用 nominatim 不会 return 响应。我想使用 nominatim,因为它 return 是一种更准确的反向地理编码。
如果它 return 不是有效的 body,则查看 HTTP 响应 header。我猜你违反了 Nominatim's usage policy。您提供有效的 HTTP 用户代理吗?