I am trying to fetch lat
and lng
of the orderRequest
address to show the admin from where the OrderRequest
is coming.
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) {
}
});
}
Admin expecting to see order loaction but output is JSONException: Index 0 out of range [0..0)