Integrating Google Maps SDK in React Native: A Complete Guide

Table of Contents
Big thanks to our contributors those make our blogs possible.

Our growing community of contributors bring their unique insights from around the world to power our blog. 

Introduction

Location-based experiences are at the heart of many mobile apps, from ride-sharing to travel guides and delivery services. With React Native, you can build cross-platform applications that leverage native performance—but integrating complex native SDKs, like Google Maps, requires careful setup and configuration. In this guide, we’ll walk through everything you need to seamlessly embed Google Maps into your React Native app: installing dependencies, configuring native projects (iOS and Android), rendering maps, handling markers and user location, and optimizing performance. By the end, you’ll have a fully functional map module ready for production.

Why Use Google Maps SDK in React Native?

  • Native performance: Unlike web-based maps, the Google Maps SDKs render using native components for smoother interactions.
  • Rich feature set: Access advanced features like heatmaps, clustering, street view, and custom tile overlays.
  • Consistent cross-platform API: Libraries like react-native-maps wrap both Google Maps (Android/iOS) and Apple Maps (iOS), letting you write one codebase.
  • Community support: A large ecosystem of plugins, examples, and StackOverflow threads to troubleshoot.

Prerequisites

Before diving in, ensure you have:

  • React Native CLI (not Expo) project set up: bashCopyEditnpx react-native init MyMapApp
  • Node.js and Yarn or npm installed.
  • Xcode (for iOS) and Android Studio (for Android) with SDKs configured.
  • A Google Cloud Platform account for obtaining Maps API keys.
  1. Install the library: bashCopyEdityarn add react-native-maps # or npm install react-native-maps --save
  2. Link native modules (React Native ≤0.59): bashCopyEditreact-native link react-native-maps For React Native ≥0.60, autolinking handles this. You can skip manual linking and proceed to native configuration.
  3. Install CocoaPods (iOS): bashCopyEditcd ios pod install cd ..

Step 2: Configure Android

2.1 Add Google Play Services Dependency

In android/app/build.gradle, under dependencies, add:

gradleCopyEditimplementation project(':react-native-maps')
implementation 'com.google.android.gms:play-services-maps:17.0.1'
implementation 'com.google.android.gms:play-services-location:18.0.0'

2.2 Register API Key

In android/app/src/main/AndroidManifest.xml, inside <application>:

xmlCopyEdit<meta-data
    android:name="com.google.android.geo.API_KEY"
    android:value="YOUR_ANDROID_API_KEY"/>

Replace YOUR_ANDROID_API_KEY with your Google Maps Android API key.

2.3 Ensure Permissions

Also in AndroidManifest.xml, add:

xmlCopyEdit<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

Step 3: Configure iOS

3.1 Update AppDelegate

In ios/MyMapApp/AppDelegate.m, import Google Maps and provide your API key:

objectiveCopyEdit#import <GoogleMaps/GoogleMaps.h>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [GMSServices provideAPIKey:@"YOUR_IOS_API_KEY"];
  // ...
}

3.2 Info.plist Modifications

In ios/MyMapApp/Info.plist, add:

xmlCopyEdit<key>NSLocationWhenInUseUsageDescription</key>
<string>App needs location access to show your position on the map</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>App needs location access to provide map features</string>

3.3 CocoaPods Verification

Ensure your Podfile includes the Maps pod:

rubyCopyEdittarget 'MyMapApp' do
  pod 'react-native-maps', path: '../node_modules/react-native-maps'
  pod 'GoogleMaps'       # Uncomment if using Google Maps SDK
  pod 'Google-Maps-iOS-Utils'
end

Then run:

bashCopyEditcd ios
pod install
cd ..

Step 4: Render a Basic Map in React Native

With native configuration complete, let’s render the map component.

4.1 Import and Render

Create or update App.js:

jsxCopyEditimport React from 'react';
import { StyleSheet, View } from 'react-native';
import MapView, { PROVIDER_GOOGLE } from 'react-native-maps';

export default function App() {
  return (
    <View style={styles.container}>
      <MapView
        provider={PROVIDER_GOOGLE}
        style={styles.map}
        initialRegion={{
          latitude: 37.78825,
          longitude: -122.4324,
          latitudeDelta: 0.0922,
          longitudeDelta: 0.0421,
        }}
      />
    </View>
  );
}

const styles = StyleSheet.create({
  container: { flex: 1 },
  map: { flex: 1 },
});

4.2 Key Props

  • provider: PROVIDER_GOOGLE for Google Maps.
  • initialRegion: Defines the map’s initial viewport.
  • style: Full-screen (or container-fit) styling.

Step 5: Displaying Markers and Callouts

Markers let you pinpoint locations; callouts display details upon tap.

5.1 Adding a Marker

jsxCopyEdit<MapView /* ... */>
  <MapView.Marker
    coordinate={{ latitude: 37.78825, longitude: -122.4324 }}
    title="San Francisco"
    description="This is a description"
  />
</MapView>

5.2 Custom Callout

jsxCopyEdit<MapView.Marker coordinate={coords}>
  <MapView.Callout>
    <View style={{ width: 150 }}>
      <Text style={{ fontWeight: 'bold' }}>Location Title</Text>
      <Text>More details here</Text>
    </View>
  </MapView.Callout>
</MapView.Marker>

5.3 Custom Marker Icons

jsxCopyEdit<MapView.Marker
  coordinate={coords}
  image={require('./assets/custom-pin.png')}
/>

Step 6: Showing User Location and Permissions

6.1 Enable User Location

jsxCopyEdit<MapView
  /* ... */
  showsUserLocation={true}
  followsUserLocation={true}
/>

6.2 Request Runtime Permissions (Android)

Use react-native-permissions or built-in PermissionsAndroid:

jsxCopyEditimport { PermissionsAndroid, Platform } from 'react-native';

async function requestLocationPermission() {
  if (Platform.OS === 'android') {
    const granted = await PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
      { title: 'Location Permission', message: 'We need your location to show it on the map' }
    );
    return granted === PermissionsAndroid.RESULTS.GRANTED;
  }
  return true;
}

useEffect(() => {
  requestLocationPermission();
}, []);

Step 7: Advanced Features

7.1 Polylines and Routes

Draw routes or lines on the map:

jsxCopyEdit<MapView.Polyline
  coordinates={[{lat:37.78, lng:-122.43}, {lat:37.79, lng:-122.44}]}
  strokeColor="#000"
  strokeWidth={3}
/>

7.2 Polygon Overlays

Highlight areas:

jsxCopyEdit<MapView.Polygon
  coordinates={[
    { latitude: 37.78825, longitude: -122.4324 },
    { latitude: 37.78925, longitude: -122.4334 },
    { latitude: 37.78825, longitude: -122.4344 },
  ]}
  fillColor="rgba(100,100,200,0.3)"
  strokeColor="#000"
/>

7.3 Heatmaps

Visualize density data:

jsxCopyEditimport { Heatmap } from 'react-native-maps';

<Heatmap points={[{latitude:37.78, longitude:-122.43, weight:1}, ...]} />

7.4 Clustering Large Marker Sets

Use community packages like supercluster or react-native-map-clustering to group markers for performance.

Step 8: Performance Optimization

  • Limit markers/polylines: Thousands of overlays slow rendering; cluster or virtualize.
  • Use LiteMode on Android: For static, non-interactive maps, reduces memory usage: xmlCopyEdit<meta-data android:name="com.google.android.gms.maps.liteMode" android:value="true"/>
  • Throttle region changes: Debounce onRegionChange callbacks to prevent excessive re-renders.
  • Image caching: Use fast local images or optimized remote caching libraries to load custom markers.

Troubleshooting Common Issues

SymptomPossible CauseSolution
Blank Map on iOSMissing API key in AppDelegate.mEnsure [GMSServices provideAPIKey:] runs
“API key not authorized” errorWrong package name / bundle IDVerify SHA-1 certificate and package names in Google Cloud Console
Markers don’t show on AndroidIncorrect resource pathPlace custom images in android/app/src/main/res/drawable
Map flickers on rotationStateful props passed directlyUse PureComponent or React.memo to optimize

Conclusion

Integrating Google Maps SDK into a React Native app unlocks powerful location-based features, from customer mapping to dynamic route planning. By following this guide—installing react-native-maps, configuring native projects, rendering maps and markers, handling permissions, and optimizing performance—you’ll build a robust, production-ready mapping experience. As you expand your app, explore advanced overlays, clustering strategies, and real-time geolocation to delight users and stand out in the marketplace.

Let's connect on TikTok

Join our newsletter to stay updated

Sydney Based Software Solutions Professional who is crafting exceptional systems and applications to solve a diverse range of problems for the past 10 years.

Share the Post

Related Posts