Я пытаюсь сделать свою первую настоящую программу, поэтому легко на меня. Эта часть преобразует введенный почтовый индекс в координаты lat/lng с использованием API Google и волейбола, но я не могу понять, как заставить функции залпа «возвращать» координаты. Из того, что я прочитал, мне нужно реализовать некоторый метод обратного вызова, но я не могу понять, как это сделать.Получение возвращаемого значения из volley onResponse
//Converts values in TextView to String
locationurl = address.getText().toString();
//RequestQueue Variable
RequestQueue mRequestQueue;
// Instantiate the cache and set up the network to use HttpURLConnection as the HTTP client.
Cache cache = new DiskBasedCache(getCacheDir(), 1024 * 1024); // 1MB cap
BasicNetwork network = new BasicNetwork(new HurlStack());
//Instantiate the RequestQueue with the cache and network
mRequestQueue = new RequestQueue(cache, network);
//Start Queue
mRequestQueue.start();
String addressurl = "http://maps.googleapis.com/maps/api/geocode/json?address=" + location;
//Formulate the request and handle the response
StringRequest address = new StringRequest(Request.Method.GET, addressurl,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
coordinates = parseLocation(response);
if((coordinates == null && coordinates.isEmpty())||coordinates.equals("NOT_VALID_ADDRESS")) {
showAlert("Please Enter A Valid Zip Code");
} else {
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
showAlert("Error."); //Error code display
//TODO: fix error handling
}
});
mRequestQueue.add(address); //Add address to ResponseQueue
'new Response.Listener()' ** is ** обратный вызов –