Для работы с Yandex API не могу написать метод . Для работы с API использую библиотеку
Volley .Сейчас у меня так :
GeoCoder.java
public class GeoCoder {
public static void getLocations(String part, final VolleyCallback callback) {
StringBuilder stringbuilder = new StringBuilder("http://geocode-maps.yandex.ru/1.x/?geocode=");
stringbuilder.append(part);
stringbuilder.append((new StringBuilder("&lang=ru")));
stringbuilder.append("&format=json&kind=street&results=10&&ll=76.9120338,43.2520096");
String url = stringbuilder.toString();
Log.e("URL", url);
JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONObject("response").getJSONObject("GeoObjectCollection").getJSONArray("featureMember");
ArrayList<Address> arrayList = new ArrayList<Address>(jsonArray.length());
for (int i = 0; i < jsonArray.length(); i++) {
Address address = new Address();
address.setAddressLine(jsonArray.getJSONObject(i).getJSONObject("GeoObject").getJSONObject("metaDataProperty").getJSONObject("GeocoderMetaData").getJSONObject("AddressDetails").getJSONObject("Country").getString("AddressLine"));
address.setCountry(jsonArray.getJSONObject(i).getJSONObject("GeoObject").getJSONObject("metaDataProperty").getJSONObject("GeocoderMetaData").getJSONObject("AddressDetails").getJSONObject("Country").getString("CountryName"));
arrayList.add(address);
}
callback.onSuccess(arrayList);
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// Handle error
}
});
VolleyApplication.getInstance().getRequestQueue().add(jsObjRequest);
}
public interface VolleyCallback {
void onSuccess(ArrayList<Address> result);
}
}
Использование GeoCoder.java
ArrayList<Address>addresses;
GeoCoder.getLocations(address,new GeoCoder.VolleyCallback() {
@Override
public void onSuccess(ArrayList<Address>result) {
addresses= result;
}
});
Как сделать так чтобы было :ArrayList<Address>results = GeoCoder.getLocations(address) ;