pseudocode
pseudocode

Reputation: 219

Android - Google Map API Key doesn't work

I have a Google Map API Key (for Android app) and I restrainted the key as Android Apps. I want to use it this link:

https://maps.googleapis.com/maps/api/elevation/json?locations=39.7391536,-104.9847034&key=MY_API_KEY

But I am getting error like this:

{
   "error_message" : "This IP, site or mobile application is not authorized to use this API key. Request received from IP address 176.233.211.37, with empty referer",
   "results" : [],
   "status" : "REQUEST_DENIED"
}

I am researching this error for hours but I couldn't solve it. Thanks in advance.

Upvotes: 1

Views: 1296

Answers (1)

Ville N.
Ville N.

Reputation: 714

Keys with Android application restrictions are only used to authorize the use of native Google APIs for Android, such as those in Google Play Services, e.g., Maps Android API and Places API for Android, whereas the Elevation API web service, which you just access over HTTP(S), is not considered to be one of these.

Just follow the Get a Key workflow to create a key that works together with the Elevation API, but as explained on the page and the best practices for securely using API keys, you should take care to protect your API key against abuse.

As explained in the Get a Key article and the Google Maps APIs FAQ, web services allow setting IP address restrictions on API keys. However, if you intend to call the Elevation API directly from your Android app, you can't know the used IP addresses, so you must leave the key unrestricted.

A safer approach would be to make the calls via your own proxy server, which allows you to set IP address restrictions on the key, and completely eliminates the need for including the API key in your mobile app, as you only need to configure it on the server.

Upvotes: 4

Related Questions