All integrations MapLibre Leaflet OpenLayers React Vue Svelte Angular React Native WordPress Webflow Squarespace Wix Shopify API docs

ExpressMaps in React Native

@maplibre/maplibre-react-native draws maps with MapLibre Native on iOS and Android, and takes an ExpressMaps style URL directly. The map below is the web version of the Standard style, to show what your app will draw.

1. Install

The examples are for MapLibre React Native 11, the current major version. It supports the New Architecture only and needs React Native 0.80 or later (Expo SDK 54 or later). Projects on the old architecture need version 10, whose components have different names (MapView, styleURL, MarkerView).

Expo: MapLibre React Native contains native code, so it does not run in Expo Go. Install it, add its config plugin, and use a development build:

npx expo install @maplibre/maplibre-react-native
// app.json
{
  "expo": {
    "plugins": ["@maplibre/maplibre-react-native"]
  }
}
# build and run locally
npx expo run:ios
npx expo run:android

# or build in the cloud with EAS
eas build --profile development --platform all

Rebuild after adding or updating the package; a JavaScript reload is not enough when native code changes.

Bare React Native: install the package and the iOS pods. Autolinking handles the rest.

npm install @maplibre/maplibre-react-native
cd ios && pod install

2. Show a map

Pass the style URL to the Map component's mapStyle prop, and set the starting view with Camera. Coordinates are [lng, lat]. In Expo, variables prefixed with EXPO_PUBLIC_ in .env are available as process.env.

// ExpressMap.jsx
import { StyleSheet } from "react-native";
import { Camera, Map } from "@maplibre/maplibre-react-native";

const KEY = process.env.EXPO_PUBLIC_EXPRESSMAPS_KEY;
const styleUrl = (id) => `https://tiles.expressmaps.com/styles/${id}.json?key=${KEY}`;

export default function ExpressMap({ mapStyle = "standard" }) {
  return (
    <Map style={styles.map} mapStyle={styleUrl(mapStyle)}>
      <Camera initialViewState={{ center: [-0.1276, 51.5072], zoom: 12 }} />
    </Map>
  );
}

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

Tiles, icons and fonts are all referenced from inside the style, so the style URL is the only one you need. If you use the optional expressmaps package elsewhere, its styleUrl("standard", KEY) helper works here too; its createMap and StyleSwitcher are for MapLibre GL JS on the web.

Markers and popups

Marker places a React Native view at a coordinate. There is no built-in popup to match the web version, so the usual pattern is a pressable marker that opens a card of your own:

import { useState } from "react";
import { Pressable, StyleSheet, Text, View } from "react-native";
import { Camera, Map, Marker } from "@maplibre/maplibre-react-native";

const OFFICE = [-0.1276, 51.5072];

export default function OfficeMap() {
  const [open, setOpen] = useState(false);

  return (
    <View style={styles.container}>
      <Map style={styles.map} mapStyle={styleUrl("standard")}>
        <Camera initialViewState={{ center: OFFICE, zoom: 12 }} />
        <Marker lngLat={OFFICE} anchor="bottom" onPress={() => setOpen(true)}>
          <View style={styles.pin} />
        </Marker>
      </Map>
      {open && (
        <Pressable style={styles.card} onPress={() => setOpen(false)}>
          <Text style={styles.title}>Our office</Text>
          <Text>Open 9 to 5</Text>
        </Pressable>
      )}
    </View>
  );
}

const styles = StyleSheet.create({
  container: { flex: 1 },
  map: { flex: 1 },
  pin: { width: 22, height: 22, borderRadius: 11, backgroundColor: "#1a73e8", borderWidth: 3, borderColor: "#fff" },
  card: { position: "absolute", left: 16, right: 16, bottom: 32, padding: 16, borderRadius: 12, backgroundColor: "#fff" },
  title: { fontWeight: "600", marginBottom: 4 }
});

Marker uses a native view per marker, which suits a handful of points. For hundreds of points, draw them as a layer, which the map renders itself:

import { GeoJSONSource, Layer } from "@maplibre/maplibre-react-native";

<GeoJSONSource id="stores" data="https://example.com/stores.geojson">
  <Layer
    id="stores"
    type="circle"
    paint={{ "circle-radius": 6, "circle-color": "#1a73e8", "circle-stroke-width": 2, "circle-stroke-color": "#fff" }}
  />
</GeoJSONSource>

Switching style

Change the mapStyle prop and the map reloads in the new style. To follow the phone's light or dark setting:

import { useColorScheme } from "react-native";

const scheme = useColorScheme();
<Map style={styles.map} mapStyle={styleUrl(scheme === "dark" ? "darklands" : "standard")} />

Any of the ten styles work: standard, basic, enhanced, darklands, greyscale, navigator, subtle, autobahn, lithium and mulberry.

API keys for apps

Web keys are protected by referrer (domain) restrictions. Native apps send no referrer, so a request from an app using a referrer-restricted key is refused with HTTP 403. For an app:

  • Create a separate key in the console for each app, with no referrer restrictions.
  • Do not reuse that key on a website, and keep it out of public repositories. It is compiled into the app, so treat it as visible to anyone who unpacks the app.
  • Watch the key's usage in the console. If it is being misused, disable it or replace it with a new key in your next release.

Things to know

  • One map load is counted each time a Map is mounted. Switching style on a mounted map does not count as another load, and panning and zooming are free. Unmounting and remounting a map screen counts again.
  • The free plan includes 100,000 map loads a month.
  • Keep the attribution button on (the attribution prop of Map). The OpenStreetMap credit comes from the style and is required by the data licence.
  • For Android, MapLibre Native needs API level 23 or later.
  • If the map is blank, check that the key has no referrer restrictions and that the app was rebuilt after installing the package.

Building for the web as well? The React guide and MapLibre GL JS guide use the same style URLs. Sign up for a free API key to get started.

Get a free API key MapLibre guide