Integrating React Native Maps & Multiple Custom Markers Like GarageDeals
In location-centric mobile apps like GarageDeals, interactive maps are the primary driver of user engagement. When buyers open the app, they want to immediately visualize neighborhood garage sales, tap custom price or item count badges, and preview listing details in real time. In this tutorial, we will walk through the end-to-end implementation of react-native-maps with multiple custom markers, interactive callout cards, and key performance optimizations.
1. Installation and Native Platform Setup
Start by adding `react-native-maps` to your project using npm or yarn:
npm install react-native-maps
# For iOS with CocoaPods
cd ios && pod install && cd ..On Android, add your Google Maps API key inside the `<application>` tag of `android/app/src/main/AndroidManifest.xml`:
<!-- android/app/src/main/AndroidManifest.xml -->
<application ...>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="YOUR_GOOGLE_MAPS_API_KEY" />
</application>On iOS, if you want to use Google Maps instead of Apple Maps, add `pod 'GoogleMaps'` to your `ios/Podfile` (and run `pod install` in `ios/`). Depending on your React Native version, initialize GMSServices in either `AppDelegate.swift` or `AppDelegate.mm`:
Option A: For modern React Native templates (0.77+) using AppDelegate.swift:
// ios/AppName/AppDelegate.swift
import UIKit
import React
import React_RCTAppDelegate
import ReactAppDependencyProvider
import GoogleMaps
@main
class AppDelegate: RCTAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
) -> Bool {
// Initialize Google Maps SDK before initializing the React Native bridge
GMSServices.provideAPIKey("YOUR_GOOGLE_MAPS_API_KEY")
self.moduleName = "AppName"
self.dependencyProvider = RCTAppDependencyProvider()
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}Option B: For React Native versions using Objective-C++ AppDelegate.mm:
// ios/AppName/AppDelegate.mm
#import "AppDelegate.h"
#import <GoogleMaps/GoogleMaps.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Initialize Google Maps SDK before initializing the React Native bridge
[GMSServices provideAPIKey:@"YOUR_GOOGLE_MAPS_API_KEY"];
self.moduleName = @"AppName";
self.initialProps = @{};
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
@end2. Defining Data Model for Hyperlocal Deals
In a marketplace like GarageDeals, each marker represents a garage sale event containing geographic coordinates, a banner image, price range, and item availability count. Let's define the TypeScript types and sample state:
export interface GarageSaleMarker {
id: string;
title: string;
address: string;
itemCount: number;
latitude: number;
longitude: number;
schedule: string;
}
export const MOCK_SALES: GarageSaleMarker[] = [
{
id: 'sale-1',
title: 'Vintage Furniture & Collectibles',
address: '742 Evergreen Terrace',
itemCount: 24,
latitude: 37.78825,
longitude: -122.4324,
schedule: 'Sat-Sun: 9 AM - 4 PM',
},
{
id: 'sale-2',
title: 'Huge Multi-Family Yard Sale',
address: '104 Main Street',
itemCount: 50,
latitude: 37.78950,
longitude: -122.4350,
schedule: 'Saturday Only: 8 AM - 2 PM',
},
];3. Rendering MapView with Custom Markers
By default, `<Marker>` renders standard platform pins. To build a branded experience like GarageDeals, pass custom React Native components as children to `<Marker>`. We can create a styled badge showing the number of available items:
import React, { useState } from 'react';
import { StyleSheet, View, Text, Alert } from 'react-native';
import MapView, { Marker, Callout, PROVIDER_GOOGLE } from 'react-native-maps';
import { MOCK_SALES, GarageSaleMarker } from './types';
export default function GarageDealsMap() {
const [sales] = useState<GarageSaleMarker[]>(MOCK_SALES);
return (
<View style={styles.container}>
<MapView
provider={PROVIDER_GOOGLE}
style={styles.map}
initialRegion={{
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 0.04,
longitudeDelta: 0.04,
}}
>
{sales.map((sale) => (
<Marker
key={sale.id}
coordinate={{
latitude: sale.latitude,
longitude: sale.longitude,
}}
tracksViewChanges={false}
>
{/* Custom Marker Pin */}
<View style={styles.markerContainer}>
<Text style={styles.markerEmoji}>🏷️</Text>
<Text style={styles.markerCount}>{sale.itemCount} items</Text>
</View>
{/* Interactive Callout Card */}
<Callout
tooltip
onPress={() => Alert.alert('Navigate', `Viewing ${sale.title}`)}
>
<View style={styles.calloutBox}>
<Text style={styles.calloutTitle}>{sale.title}</Text>
<Text style={styles.calloutAddress}>{sale.address}</Text>
<Text style={styles.calloutSchedule}>{sale.schedule}</Text>
<Text style={styles.calloutAction}>Tap to view listing →</Text>
</View>
</Callout>
</Marker>
))}
</MapView>
</View>
);
}4. Styling Custom Marker Badges & Callout Tooltips
Using `tooltip={true}` on `<Callout>` strips default OS bubble styling, giving you full control over the popup design using standard React Native StyleSheet styles:
const styles = StyleSheet.create({
container: {
...StyleSheet.absoluteFillObject,
justifyContent: 'flex-end',
alignItems: 'center',
},
map: {
...StyleSheet.absoluteFillObject,
},
markerContainer: {
backgroundColor: '#0f172a',
paddingHorizontal: 10,
paddingVertical: 6,
borderRadius: 20,
flexDirection: 'row',
alignItems: 'center',
borderWidth: 2,
borderColor: '#ffffff',
shadowColor: '#000',
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.25,
shadowRadius: 3.84,
elevation: 5,
},
markerEmoji: {
fontSize: 14,
marginRight: 4,
},
markerCount: {
color: '#ffffff',
fontSize: 12,
fontWeight: '700',
},
calloutBox: {
backgroundColor: '#ffffff',
borderRadius: 12,
padding: 14,
width: 220,
shadowColor: '#000',
shadowOffset: { width: 0, height: 4 },
shadowOpacity: 0.15,
shadowRadius: 8,
elevation: 6,
},
calloutTitle: {
fontSize: 14,
fontWeight: '700',
color: '#0f172a',
marginBottom: 4,
},
calloutAddress: {
fontSize: 12,
color: '#64748b',
marginBottom: 4,
},
calloutSchedule: {
fontSize: 11,
fontWeight: '600',
color: '#16a34a',
marginBottom: 8,
},
calloutAction: {
fontSize: 12,
fontWeight: '600',
color: '#4f46e5',
},
});5. Critical Performance Optimizations for Map-Heavy Apps
When rendering 50+ markers across a busy metropolitan area, apps can suffer from stuttering frame rates. Here are three critical performance techniques we used when developing GarageDeals:
1. `tracksViewChanges={false}`: By default, React Native continuously recalculates the layout of custom child views on every single frame. Once your marker's assets or icons finish loading, set `tracksViewChanges={false}` to lock in the rasterized bitmap on the native thread. This single property can reduce CPU utilization by over 60%.
2. Map Marker Clustering: Instead of rendering 200 overlapping markers when zoomed out, use a clustering algorithm (like Supercluster or `react-native-map-clustering`). Clustered markers collapse nearby sales into a single numerical badge (e.g., '+12 sales in this neighborhood') and expand dynamically as the user zooms in.
3. Bounding-Box Querying (Geo-queries): Only fetch and render markers that fit inside the currently visible viewport (`onRegionChangeComplete`). Filter coordinates using backend spatial indexes (such as MongoDB `$geoWithin` or PostGIS `ST_MakeEnvelope`) so the mobile app only handles markers currently visible to the shopper.