【发布时间】:2016-02-16 21:02:48
【问题描述】:
由于某种原因,Api 会以不同的坐标来响应我发送的坐标。我已经调试了应用程序,调用 api 的结果与 JSON 文件中返回的结果不同。例如 发送者:
返回的人
-
{"coord":{"lon":24.76,"lat":60.15},"weather":....... 这是我目前使用的代码:
私有静态最终字符串 OPEN_WEATHER_MAP_API = "http://api.openweathermap.org/data/2.5/weather?q=";
URL url = new URL(String.format(OPEN_WEATHER_MAP_API + "lat="+lat+"&"+"lon="+lon)); HttpURLConnection connection = (HttpURLConnection)url.openConnection(); connection.addRequestProperty("x-api-key", context.getString(R.string.open_weather_maps_app_id)); BufferedReader reader = new BufferedReader( new InputStreamReader(connection.getInputStream())); StringBuffer json = new StringBuffer(1024); String tmp=""; while((tmp=reader.readLine())!=null) json.append(tmp).append("\n"); reader.close(); JSONObject data = new JSONObject(json.toString());
【问题讨论】:
标签: android android-fragments location