ava
ava

Reputation: 1176

Google Map API Key in Directions (iOS app)

i want to use google map api for route between two location. in my IOS application. i try create public key for project and enable uses API in developer console. but i got this error: this ip site or mobile application is not authorized to use this api key IOS. after this error i try create API key for Key restriction for (IP addresses (web servers, cron jobs, etc.)) and set my ip address and then routing is work fine. but when i try this from other device again and again i get this error. i should use this URL for routing :

let url = "https://maps.googleapis.com/maps/api/directions/json?origin=\(origin)&destination=\(destination)&mode=driving&key=APIKEY"

how can solve this problem for working my code in all devices.

Upvotes: 0

Views: 2044

Answers (1)

xomena
xomena

Reputation: 32178

The API key that you use with Google Maps web service (Directions API) supports an IP restriction as mentioned in the following document:

https://developers.google.com/maps/faq#using-google-maps-apis

The issue is that you cannot know the IP addresses of all devices where your application is installed.

You have the following options:

  1. Use unrestricted API key. Note that API key requires HTTPS connection, so the API key won't be intercepted from the request itself, because the request is encrypted. So, in this case you should procure that the API key is not put directly in your source code. If you can read it from config or the environment, it might be feasible.

  2. Create an intermediate server. Your iOS application should send requests to the intermediate server, intermediate server should send requests to Google and pass responses back to your app. In this case you can restrict an API key by IP address of your intermediate server.

I hope this helps!

Upvotes: 1

Related Questions