In my Android application I use the Directions API to calculate the traveltime to location A to B by car.
Now I am trying to build a new feature using public transportation and with the Directions API you can do this by adding &mode=transit
. After I done this I get an error saying I have to use an API key. So I added my Android application API key to my code using &key=***
.
Unfortunately my application gives the following response:
"This IP, site or mobile application is not authorized to use this API key."
At my Android application API key the right fingerprint is there.
Then I thought it is a HTTP request so am I not supposed to use the "Key for browser applications". So I went and tried that but then I get the same error. While Referers says: "Any referer allowed".
My code:
AsyncHttpClient client = new AsyncHttpClient();
client.get("https://maps.googleapis.com/maps/api/distancematrix/json?origins="+ latlong +"&destinations="+ location +"&key=***&sensor=true&units=metric&language=nl&mode=" + mode, new AsyncHttpResponseHandler() {
@Override
public void onStart() {}
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] response) {}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {}
}
Here is the JSON response:
{
"destination_addresses" : [],
"error_message" : "This IP, site or mobile application is not authorized to use this API key.",
"origin_addresses" : [],
"rows" : [],
"status" : "REQUEST_DENIED"
}
So which key am I supposed to use and how can I get this to work properly?
Thanks in advance!