实际上我正在研究android应用程序,其中我必须计算用户的当前lat / lon并计算nearBy Lat / Lon(已在ArrayList中设置)的距离,以便计算我使用Distance api的距离。 ... 以上所有事情都运作良好,但问题是
Java代码:
//Iterate List and call the getDirection function
for (ProviderItem item : workshopList) {
toLat=item.getLat();
toLon=item.getLon();
getDirection(current_Lat,current_Lon,toLat,toLon);
//now after that i have to set the volley response in item.setDirection();
}
private void getDirection(fromLatitude, fromLongitude, toLatitude, toLongitude){
String url = makeURL(fromLatitude, fromLongitude, toLatitude, toLongitude);
StringRequest stringRequest = new StringRequest(url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d("Response",response);
final JSONObject json = new JSONObject(result);
JSONArray routeArray = json.getJSONArray("routes");
JSONObject routes = routeArray.getJSONObject(0);
JSONArray legsArray = routes.getJSONArray("legs");
JSONObject legs = legsArray.getJSONObject(0);
JSONObject distanceObj = legs.getJSONObject("distance");
String parsedDistance=distanceObj.getString("text");
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
注意: