Мне нужно получить широту и долготу из: public void onLocationChanged(Location location)
и перенести их в другой метод (анализатор JSON), чтобы его можно было применить к URL для API погоды.Что ваши парни предлагают для этого?Я довольно новичок в этом, пример был бы очень признателен.
@Override
public void onLocationChanged(Location location) {
url = "https://api.openweathermap.org/data/2.5/weather?lat=" + location.getLatitude() + "&lon=" + location.getLongitude() + "&appid=5d8fea5f1c9cdfe8af473504e5f9002a";
Log.i("api", url);
//double lat = location.getLatitude();
// double lng = location.getLongitude();
}
@Override
public void onStatusChanged(String s, int i, Bundle bundle) {
}
@Override
public void onProviderEnabled(String s) {
}
@Override
public void onProviderDisabled(String s) {
}
Мне нужен URL-адрес от метода Location до JsonObjectRequest
private void jsonParse() {
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONObject weatherData = response.getJSONObject("main");
double temp = weatherData.getDouble("temp");
double tempHigh = weatherData.getDouble("temp_max");
double tempLow = weatherData.getDouble("temp_min");
double humidity = weatherData.getDouble("humidity");
Log.i("JSONWork", String.valueOf(weatherData));
TV_temp_max.append("Highest Temperature: " + tempHigh);
TV_temp_min.append("Lowest Temperature: " + tempLow);
TV_temp.append("Current Temperature: " + temp);
TV_humidity.append("Humidity: %" + humidity);
JSONObject locationData = response.getJSONObject("sys");
String country = locationData.getString("country");
String city = locationData.getString("name");
TV_country.append(country);
TV_city.append(city);
} catch (JSONException e) {
Log.i("error", "JSON is not working");
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});
mQueue.add(request);
}