【发布时间】:2019-12-05 21:39:52
【问题描述】:
我正在尝试获取orderRequest 地址的lat 和lng,以向管理员显示OrderRequest 的来源。
private void drawRoute(LatLng yourLocation, String address) {
mServices.getGoeCode(address).enqueue(new Callback<String>() {
@Override
public void onResponse(Call<String> call, Response<String> response) {
try{
JSONObject jsonObject = new JSONObject(response.body().toString());
String lat = ((JSONArray)jsonObject.get("results"))
.getJSONObject(0)
.getJSONObject("geometry")
.getJSONObject("location")
.get("lat").toString();
String lng = ((JSONArray)jsonObject.get("results"))
.getJSONObject(0)
.getJSONObject("geometry")
.getJSONObject("location")
.get("lng").toString();
LatLng employeeLocation = new LatLng(Double.parseDouble(lat),Double.parseDouble(lng));
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.box);
bitmap = Common.scaleBitmap(bitmap,70,70);
MarkerOptions markerOptions = new MarkerOptions().icon(BitmapDescriptorFactory.fromBitmap(bitmap))
.title("Order of current person")
.position(employeeLocation);
mMap.addMarker(markerOptions);
}catch (JSONException e){
Toast.makeText(MapsActivity.this, "Error : "+e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<String> call, Throwable t) {
}
});
}
管理员希望看到订单位置,但输出是 JSONException: Index 0 out of range [0..0)
【问题讨论】:
-
发布您的 JSON。听起来好像是空的。
标签: java android json google-maps jsonexception