【发布时间】:2020-07-28 09:51:58
【问题描述】:
如何在 android 应用程序的字符串地名中获取值“A Salam St, Sib, Oman”。 json 响应附加为图像。请检查 {
String URL="https://maps.googleapis.com/maps/api/geocode/json?latlng="+myLat+","+myLong+"&&key=XXX";
RequestQueue requestQueue= Volley.newRequestQueue(MercahntUpdate.this);
//etMID.setText("");
JsonObjectRequest objectRequest=new JsonObjectRequest(
Request.Method.GET, URL, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.e("success",response.toString());
String loudScreaming = response.optJSONArray("results[0].address_components.formatted_address").toString();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("error",error.toString());
}
}
);
【问题讨论】:
-
首先使用密钥
"results"从response获取JSONArray。然后从该数组的 0 索引中获取JSONObject。然后使用密钥"formatted_address"从JSONObject访问所需的String。
标签: android json api android-volley geocode