I've been trying to install google maps for react-native for a week an still no success. I've searched and tried the solutions in the react-native-maps github issue but still I get a blank page.
What I do:
react-native init myapp
npm install
yarn add react-native-maps
react-native link react-native-maps
In Google Console APIs -> Create new Project -> Enable Google Maps Android API, Google Maps JavaScript API and Places API -> Create credentials
In AndroidManifest.xml
<application>
....
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="XXX"/>
</application>
package.json
{
"name": "maps",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "16.0.0",
"react-native": "0.50.4",
"react-native-maps": "^0.18.3"
},
"devDependencies": {
"babel-jest": "21.2.0",
"babel-preset-react-native": "4.0.0",
"jest": "21.2.1",
"react-test-renderer": "16.0.0"
},
"jest": {
"preset": "react-native"
}
}
App.js
import React, { Component } from 'react';
import {
StyleSheet,
Text,
View
} from 'react-native';
import MapView from 'react-native-maps'
export default class App extends Component {
render() {
return (
<View style={styles.container}>
<MapView
style={styles.map}
region={{
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 0.015,
longitudeDelta: 0.0121,
}}
>
</MapView>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
...StyleSheet.absoluteFillObject,
alignItems: 'center',
},
map: {
...StyleSheet.absoluteFillObject,
},
});
Edit: Because some people asked me for stack trace: Sample 1
This problem generally happens when you have too many bugged cookies in your browser or cached data in your Android app. The best solution to blank Google Maps is getting rid of the unwanted data from your mobile app or web browser.
Few alternatives for google maps in react native : Mapbox - https://www.npmjs.com/package/@mapbox/react-native-mapbox-gl. Yandex Map - https://www.npmjs.com/package/react-native-yandexmapkit.
I spent a whole day on trying solutions provided in google, but it seemed that legacy meta-data wasn't working for me, so I changed the line below in AndroidManifest.xml
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="Your Google maps API Key Here"/>
to
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="Your Google maps API Key Here"/>
and finally the map showed up.
Of course the Maps SDK for Android
must be enabled in Google Api Console. Here are the steps to enable Maps SDK for Android
for beginners:
Go to the Google Api Console.
on the top-left of the screen, just on the right side of Google Apis
logo, you see your project name, select the right project name and then, below the project name, you see a blue text + ENABLE APIS AND SERVICES
. Click on it.
in the webpage that opens, scroll down to find Maps SDK for Android
. Click to enable it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With