Reputation: 185
I made a taxi booking project that uses google maps api to locate cabs, pickup and drop locations.
The problem is when I request a ride the following error occurs:
This API project is not authorized to use this API
Note that I had enabled all google map api services then regenerate the key and the problem is still exist.
How to solve this?
Upvotes: 3
Views: 32170
Reputation: 185
I found the answer,
The problem was in my code at this line:
public void requestDirection() {
snackbar = Snackbar.make(view, getString(R.string.fare_calculating), Snackbar.LENGTH_INDEFINITE);
snackbar.show();
GoogleDirection.withServerKey(getString(R.string.google_api_key))
.from(origin)
.to(destination)
.transportMode(TransportMode.DRIVING)
.execute(this);
confirm.setEnabled(false);
}
R.string.google_api_key's
value was feeded by another key from strings.xml
. For now, I gave a direct value to withServerKey until I found the the problem with my strings.xml.
public void requestDirection() {
snackbar = Snackbar.make(view, getString(R.string.fare_calculating), Snackbar.LENGTH_INDEFINITE);
snackbar.show();
GoogleDirection.withServerKey("[api key]")//getString(R.string.google_api_key))
.from(origin)
.to(destination)
.transportMode(TransportMode.DRIVING)
.execute(this);
confirm.setEnabled(false);
}
Upvotes: 2
Reputation: 193
To resolve this issue if you hit polyline Api:
Need to enable the APIs:
Upvotes: 1
Reputation: 3699
If you think you have enabled all, Then you may missed changing your manifest.xml
file like :
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
Add these tags under application
tag
Upvotes: 1
Reputation: 1008
You need to enable the required APIs in the google Developer console : https://console.developers.google.com/
Select your project on the Top Left corner and then click on the "ENABLE API AND SERVICES" button in the dashboard.
Note that you may need to enable more than 1 API (Directions, Geolocating,Geocoding etc) based on your requirement.
Upvotes: 5