Search code examples
iosgoogle-mapsgoogle-maps-api-3google-cloud-platformgoogle-geocoder

why my app is always not authorized after giving Google API key restriction?


I have tried to read some similar thread about this issue. but unfortunately I still get the same issue.

so Basically, I am trying to reverse geocode of my latitude longitude into human readable address using Goole Geocode API.

to be more secure, I give more restriction on my API Key like this for my iOS app. here is the application restriction for the key

enter image description here

and I also give the API Key restriction like this, I am sure that I have include the geocoding API enter image description here

and I also have enabled the geocoding API for my project enter image description here

but when I run the app .... I got error message

This IP, site or mobile application is not authorized to use this API key. Request received from IP Address xxxxxx with empty referer

what went wrong in here ? it works fine if the restriction is set to none


Solution

  • You cannot use iOS app restrictions for Google Maps web services. It is supposed that you execute web services requests on your backend server and the only supported restriction for Geocoding API and Places API is IP address restriction.

    This fact is documented here

    https://developers.google.com/maps/api-key-best-practices#api_key_table

    In case of mobile applications Google recommends using intermediate server that proxies requests. Your app send requests to intermediate server, intermediate server send requests to Google with protected API key and pass response back to mobile app. In this case you can apply restriction by IP address of intermediate server.

    You can read about this approach on

    https://codelabs.developers.google.com/codelabs/google-maps-web-services-proxy/index.html

    I hope this answer solves your doubt.