public void get_direction(Activity _activity, GoogleMap _googleMap,
LatLng _origin,LatLng _destination,TextView _txt_distanc,TextView _txt_duration,String mode)
{
activity=_activity;
googleMap=_googleMap;
origin=_origin;
destination=_destination;
txt_distanc=_txt_distanc;
txt_duration=_txt_duration;
String o,d,key;
o=origin.latitude+","+origin.longitude;
d=destination.latitude+","+destination.longitude;
key="***";
final String url = "https://maps.googleapis.com/maps/api/directions/json?origin="+o+"&destination="+d+"&key="+key+"&mode="+mode;
final StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.i("onResponse: ",url );
Log.i("onResponse: ",response );
draw_path(response );
get_distans(response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.i("onResponse: ",url );
Log.i("VolleyError: ",error.toString() );
}
}
)
{
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String,String> map =new Hashtable<String,String>();
map.put("name", Base64.encodeToString(String.valueOf("").getBytes()
, Base64.DEFAULT));
return map;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(activity);
requestQueue.add(stringRequest);
}
My code do little time routing correctly. But after a few hours, it only routing, routes beforehand once routed, otherwise it display the following error:
{ "error_message" : "This API project is not authorized to use this API.", "routes" : [], "status" : "REQUEST_DENIED" }
The API key you have given to the url
https://maps.googleapis.com/maps/api/directions/json?origin="+o+"&destination="+d+"&key="+key+"&mode="+mode
hasn't been enabled to use Google's Navigation API. Follow this link to enable it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With