我正在使用此链接,为了将转换地址转换为GeoCodes,我稍微改变了一点:http://julien.gunnm.org/geek/programming/2015/09/13/how-to-get-geocoding-information-in-java-without-google-maps-api/
我不理解某些请求我获得了400个响应代码,而对于某些我没有任何问题。(我尝试了这些请求,它们对我来说很好)。
例如:
private String getRequest(String url) throws Exception {
url=http://nominatim.openstreetmap.org/search=42+Avenue+Foch,+Saint+Maur+Des+Fossés+France&format=json&addressdetails=1
final URL obj = new URL(url);
final HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestProperty("Content-Length", Integer.toString(url.length()));
con.setRequestMethod("GET");
InputStream is ;
if (con.getResponseCode() != 200) {
is = con.getInputStream();
} else {
is = con.getErrorStream();
}
BufferedReader in = new BufferedReader(new InputStreamReader(is));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
return response.toString();
}