Skip to content

Repository files navigation

react-native-better-maps

Your react-native-maps screen mounts a React view for every marker? Hand the map your data instead.

A replacement for react-native-maps: Apple Maps and Google Maps on iOS, Google Maps on Android, behind one typed API and rendered natively through Nitro Views. Markers, shapes and GeoJSON reach the map as data, with no view per marker and no bitmap snapshots, and clustering is built in. Markers made of live React Native views are there when you need them.

npm version npm downloads GitHub stars New Architecture License: MIT CI

Clustering • Migration • Installation • Usage • Documentation • Example app

Clustering compared

The same marker clustering scenario in react-native-better-maps and in react-native-maps with react-native-clusterer.

react-native-better-maps react-native-maps + react-native-clusterer
iOS, Apple Maps react-native-better-maps clustering on iOS Apple Maps react-native-maps with react-native-clusterer on iOS Apple Maps
Android, Google Maps react-native-better-maps clustering on Android Google Maps react-native-maps with react-native-clusterer on Android Google Maps

Migration

Remove react-native-maps, install this library, then:

- import MapView, { Marker, PROVIDER_GOOGLE } from 'react-native-maps';
+ import { MapView, Marker } from 'react-native-better-maps';

  <MapView
-   provider={PROVIDER_GOOGLE}
+   provider="google"
-   initialRegion={region}
+   region={region}
    style={{ flex: 1 }}
  >
    <Marker coordinate={coordinate} title="Warsaw" />
  </MapView>

Imports are named, and a region that keeps its value is applied once, so it also serves as the initial region. Custom marker views move to MarkerView. Migrating from react-native-maps covers methods, region events, markers and GeoJSON.

Installation

iOS 16.0+ and Android 7.0+ (API 24), React Native 0.78+ with the New Architecture, and react-native-nitro-modules 0.37.2+. Expo SDK 56+ needs a development build; Expo Go does not work.

npm install react-native-better-maps react-native-nitro-modules
cd ios && pod install && cd ..

Rebuild the native app after installing. With Expo, install with npx expo install, add the config plugin, then run npx expo prebuild and npx expo run:ios or run:android: see Setup.

Important

Google Maps needs an API key: always on Android, and on iOS with provider="google". Without one the map stays blank. The Expo config plugin writes the keys and the location permission strings for you; a bare React Native app sets them by hand. See Setup. Apple Maps needs no key.

Usage

import { MapView, Marker, Polyline } from 'react-native-better-maps';

const warsaw = { latitude: 52.2297, longitude: 21.0122 };

export function CityMap() {
  return (
    <MapView
      style={{ flex: 1 }}
      region={{ ...warsaw, latitudeDelta: 0.05, longitudeDelta: 0.05 }}
      onRegionChangeComplete={(region, details) =>
        console.log(region, details.isGesture)
      }
    >
      <Marker coordinate={warsaw} title="Warsaw" image={require('./pin.png')} />
      <Polyline
        coordinates={[warsaw, { latitude: 52.237, longitude: 21.017 }]}
        strokeColor="#FF0000"
        strokeWidth={3}
      />
    </MapView>
  );
}

iOS uses Apple Maps and Android Google Maps unless you set provider. Markers and shapes can also be passed as arrays through the markers, polylines, polygons and circles props: see Overlays.

Documentation

API reference Every component, prop, ref method, event and type
Setup The Expo config plugin, Google Maps API keys, bare React Native
Map providers Choosing Apple Maps or Google Maps, provider-specific props, Google Map IDs
Camera and region events Moving the camera from code, when its promises settle, screen points, region change events
Markers Bitmap marker images, remote image hosts, entering animations
Live JSX markers MarkerView: markers made of interactive, animated React Native views
Clustering Cluster presses and cluster badges
Overlays Overlay ids, shape presses, re-renders, invalid input
GeoJSON FeatureCollections as markers, polylines and polygons
Points of interest Taps on the map's own places, Apple's place details, filtering them
Compatibility Requirements, supported platforms and the capability matrix per provider
Migrating from react-native-maps The minimal change, methods, region events, markers, GeoJSON
Upgrading from 1.2 Behavior that changed in 1.3.0, and what to do about it
Limitations What the library does not do yet, and what's next
Troubleshooting Blank maps, Google Maps keys, Expo Go, New Architecture errors
Architecture Layers, provider adapters and the overlay pipeline; decisions in docs/adr
Example app Every feature in one Expo app, on both providers

AI coding agents learn this API and the migration from react-native-maps with the agent skill: npx skills add gmi-software/better-skills --skill react-native-better-maps.

Contributing

See CONTRIBUTING.md for the toolchain, native builds, tests and commit conventions. Releases are published from CI, see RELEASING.md. Report vulnerabilities privately, see SECURITY.md.

License

MIT, see LICENSE.


Built and maintained by GMI Software. If it saves your map screen, a ⭐ helps other React Native developers find it.

Releases

Packages

Used by

Contributors

Languages