我正在使用此url =“http://nominatim.openstreetmap.org/search?q=26+rue+du+four+75006+paris&format=json&polygon_svg=1&addressdetails=1”(例如)执行请求,并返回一个json文件,我试图解析它:
public class DepartureAddress {
String adresseDepart = OsmRoadTaskActivity.Estartpoint.getText().toString();
static double lat;
static double lng;
public DepartureAddress() {
}
public static void getGPSCoordonates(String adresseDepart) {
String adresseDepartFormate = adresseDepart.replaceAll(" ", "+");
String url = "http://nominatim.openstreetmap.org/search?q="+adresseDepartFormate+"&format=json&polygon_svg=1";
HttpGet httpget = new HttpGet(url);
HttpClient client = new DefaultHttpClient();
HttpResponse response;
StringBuilder sb = new StringBuilder();
String result = "";
try {
response = client.execute(httpget);
HttpEntity entity = response.getEntity();
InputStream stream = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(
stream, "iso-8859-1"), 8);
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
stream.close();
result = sb.toString();
}
catch (IOException e) {
e.printStackTrace();
}
try {
JSONArray jarray = new JSONArray(result);
for (int i = 0; i < jarray.length(); i++) {
JSONObject jobject = jarray.getJSONObject(i);
lat = jobject.getDouble("lat");
lng = jobject.getDouble("lon");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
但该应用程序在海洋中间放置了一个标记...... 我错过了什么? 感谢