How to restrict api key google maps for iOS in an Ionic app

I have a problem here, i can restrict calls to my google api key from my front end deployed website without any problem, but when I tried to load the map in an iphone, the origin is from ionic://localhost, the thing is that i tried to reestrict:

And no luck, the thing is that before I created an android / ios / web app in firebase, so in google console i have 3 api keys. I want to use just one api key used in my index.html as: <script async defer src="https://maps.googleapis.com/maps/api/js?XXXXXXX&libraries=places" type="text/javascript"></script> and still restrict calls at least from ios/android.

  1. I should include the same api key for android and ios in config.xml, eg: (for android inside the <platform name="android"><preference name="GOOGLE_MAPS_ANDROID_API_KEY" value="XXXXXXXXX" /></platform>) or should i use two different api keys?

  2. If I use my browser api key in de index.html and the one for android and ios (which are different) in de config.xml, i saw my billing, and google maps is ignoring the api keys in my config.xml, so i cannot separate the logic.

  3. If I use one api key declared in index.html as i said, and in preference as well in config.xml, i cannot have two different type of restrictions in google console, because I cannot have HTTP reestriction for web and IOS restriction with bundle id, because if i restrict in one way, the other dissapears (anyways the bundle id restriction doesnt work). What i want to achieve is at least restrict ios/ android api keys by http, but as i said ionic://localhost doesnt work

Upvotes: 0

Views: 1084

Answers (1)

smga08
smga08

Reputation: 624

API key restrictions to a specific bundle id or package name are only applicable for iOS or Android applications that uses Maps and Places SDKs for mobile.

Since you are implementing Google Maps with ionic you can try adding "file://" referers like this: __file_url__. For example, "file:///path/to/" should be formatted as "__file_url__//path/to/*".

More information can be found at the Note below the restriction steps here.

If you are still having issues with your key restrictions, you can directly contact Google Maps Platform support for them to be able to guide you as this issue involves your API key.

Hope this helps!

Upvotes: 0

Related Questions