Go4Food Go4Food Docs v1.0.0
Step 4 · Mobile Apps

Google Maps Key in the Apps

The phone apps need your Google Maps key inside the build to draw the native map. The same key also goes into the admin panel for address search, routes and the websites.

15 min

The apps can show Google Maps or free OpenStreetMap. You choose in the admin panel under SettingsMap Settings (Type: Google Map or OSM Map). Whatever you choose, the demo key in the apps must be replaced with your own before you publish: it belongs to the Go4Food demo project and will stop working for you.

Where the key goesUsed for
AndroidManifest.xml in each appDrawing the Google map on Android
AppDelegate.swift in each appDrawing the Google map on iPhone
Admin panel → Map Settings → Google Map KeyAddress search, street address of a pin, the route on the tracking map, and every map on the admin panel and the websites

1. Create the key#

In the Google Cloud Console, select your Firebase project, open APIs & Services → Library and enable:

APIUsed byFor
Maps SDK for AndroidCustomer, Restaurant, DriverThe map in the Android apps
Maps SDK for iOSCustomer, Restaurant, DriverThe map in the iPhone apps
Maps JavaScript APIAdmin panel, restaurant panel, customer websiteThe map on the web
Places APICustomer and Restaurant apps, admin panel, websitesAddress and place search
Geocoding APICustomer and Driver appsThe street address of a map pin
Routes APICustomer and Driver appsThe road route on the tracking map

Then APIs & Services → Credentials → Create credentials → API key, and copy the key (it starts with AIza).

Billing

Google Maps needs a billing account on the Google Cloud project. Your Firebase project is already on the Blaze plan, so it has one. Google gives a monthly free allowance per API.

2. Put it in each app#

Open android/app/src/main/AndroidManifest.xml and replace the value of the com.google.android.geo.API_KEY line inside <application>:

customer/android/app/src/main/AndroidManifest.xml
<meta-data
    android:name="com.google.android.geo.API_KEY"
    android:value="YOUR_API_KEY" />

Open ios/Runner/AppDelegate.swift and replace the key in the GMSServices.provideAPIKey line:

customer/ios/Runner/AppDelegate.swift
import GoogleMaps
...
GMSServices.provideAPIKey("YOUR_API_KEY")

Do it in customer, restaurant and driver. The line is already there in all six files; you only change the value.

3. Rebuild#

The key is read only when the app is built. Hot reload is not enough: stop the app and run it again, or build a new APK, AAB or IPA.

4. Save it in the admin panel#

Open SettingsMap Settings, paste the key into Google Map Key, pick the Type and click Save. The apps and websites read it at start-up. See Zones & map settings.

Websites need no file change

The admin panel, restaurant panel and customer website load the Google Maps script with the key from Map Settings. You do not put the key into any web/index.html.

Protect your key

Under API restrictions, restrict the key to the six APIs above, and set a budget alert in Google Cloud Billing. Do not add an Android-app, iOS-app or website restriction to the key you save in the admin panel: the apps call Places, Geocoding and Routes with it directly, and the websites use it too. If you want app restrictions, create a second key just for the two app files above.

ProblemFix
Grey map with a Google logoMaps SDK for Android / iOS is not enabled, or the key in the app file is wrong. Rebuild after fixing.
Address search finds nothingPlaces API is not enabled, or the key in Map Settings is empty or restricted.
No route line on the tracking mapRoutes API is not enabled.
"This page can't load Google Maps correctly" on a websiteMaps JavaScript API is not enabled, billing is off, or the key has a website restriction that does not include your domain.