Android 阅读谷歌地图Json
我在阅读时间和距离方面有困难,请帮忙。到目前为止,这就是我设法到达的地方Android 阅读谷歌地图Json,android,Android,我在阅读时间和距离方面有困难,请帮忙。到目前为止,这就是我设法到达的地方 String url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=-1.3070491136606004,36.824679896235466&destinations=-1.3074272067017922,36.82789519429207"; RequestQueue mRequestQueue
String url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=-1.3070491136606004,36.824679896235466&destinations=-1.3074272067017922,36.82789519429207";
RequestQueue mRequestQueue;
Cache cache = new DiskBasedCache(getActivity().getCacheDir(), 1024 * 1024); // 1MB cap
final Network network = new BasicNetwork(new HurlStack());
mRequestQueue = new RequestQueue(cache, network);
mRequestQueue.start();
StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
System.out.println("Response" + response);
JSONObject jsonObject;
JSONArray jsonarray;
try {
jsonObject = new JSONObject(response);
jsonarray = jsonObject.getJSONArray("rows");
for (int i=0; i<jsonarray.length(); i++)
{
JSONArray jsonArray = jsonarray.getJSONArray(i);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}){
@Override
protected Map<String,String> getParams(){
Map<String,String> params = new HashMap<String, String>();
return params;
}
};
// Add the request to the RequestQueue.
mRequestQueue.add(stringRequest);
继续获取元素
for (int i=0; i<jsonarray.length(); i++) {
JSONArray elements = element.getJSONObject(i).getJSONArray("elements");
JSONObject innerObj = elements.getJSONObject(0);
String distance = innerObj.getJSONObject("distance").getString("text");
String duration = innerObj.getJSONObject("duration").getString("text");
}
for(int i=0;i
for (int i=0; i<jsonarray.length(); i++) {
JSONArray elements = element.getJSONObject(i).getJSONArray("elements");
JSONObject innerObj = elements.getJSONObject(0);
String distance = innerObj.getJSONObject("distance").getString("text");
String duration = innerObj.getJSONObject("duration").getString("text");
}