I have created a mobile app using Expo and get this error when trying to use react-native-maps on an Android emulator.
I modified the app.json file as follows to include the api key as follows:
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#FFFFFF"
},
"package": "com.sjroy5.worksideclient",
"config": {
"googleMaps": {
"apiKey": "AIzaSyDyhqHd1Zk266sB-HNeBXlO2dUs0XQuUxQ"
}
},
"versionCode": 2
},
Maps work just fine on my IOS device. Any suggestions?
2
Answers
The
AndroidManifest.xml
file is located at the following pathsAND
Just editing the manifest file in the main should be enough.
The issue you’re facing is due to the fact that the config object in your app.json file is not the correct place to put the Google Maps API key. The config object is used to configure various Expo services, but it doesn’t directly configure the react-native-maps package.
Add the provider prop to the MapView component and set it to MapView.PROVIDER_GOOGLE. Finally, pass the apiKey prop to the MapView component and set it to your Google Maps API key.
If you want to keep your API key in a separate file for better security, you can do so by creating a .env file in the root of your project and adding your API key to it.
install the expo-constants package
import the Constants object from expo-constants and use it to access the API key