API Reference
Complete reference for all React Native map components and their props.
Component Anatomy
All parts of the component that you can use and combine to build your map.
<Map>
<MapMarker coordinate={[lng, lat]}>
<MarkerContent>
<MarkerLabel />
</MarkerContent>
<MarkerPopup />
</MapMarker>
<MapRoute coordinates={...} />
<MapControls />
<MapUserLocation />
</Map>Map
The root container component that initializes MapLibre React Native and provides context to child components. Automatically handles theme switching between light and dark modes based on the device color scheme.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | Child components (markers, popups, controls, routes). |
center | [number, number] | [0, 0] | Initial center coordinate [longitude, latitude]. |
zoom | number | 10 | Initial zoom level (0-20). |
styles | { light?: string | object; dark?: string | object } | — | Custom map styles for light and dark themes. Overrides the default CARTO basemap tiles. |
className | string | — | Container style (tailwindcss). |
showLoader | boolean | true | Show loading indicator while map initializes. |
useMap
A hook that provides access to the MapLibre map and camera refs, plus loading state and theme. Must be used within a Map component.
const { mapRef, cameraRef, isLoaded, theme } = useMap();
// Access map instance
const center = await mapRef.current?.getCenter();Returns an object with:
mapRef- Ref to MapLibre MapViewcameraRef- Ref to MapLibre Camera for programmatic movementisLoaded- Boolean indicating if map is loaded and readytheme- Current theme ("light" or "dark")
MapControls
Renders map control buttons (zoom in/out and locate). Must be used inside Map.
| Prop | Type | Default | Description |
|---|---|---|---|
position | "top-left" | "top-right" | "bottom-left" | "bottom-right" | "bottom-right" | Position of the controls on the map. |
showZoom | boolean | true | Show zoom in/out buttons. |
showLocate | boolean | false | Show locate button to find user's location. Requires location permissions. |
className | string | — | Additional styles for the controls container. (tailwindcss) |
onLocate | (coords: { longitude: number; latitude: number }) => void | — | Callback with user coordinates when located. |
MapMarker
A container for marker-related components. Provides context for its children and handles marker positioning.
| Prop | Type | Default | Description |
|---|---|---|---|
coordinate | [number, number] | — | Marker position as [longitude, latitude]. Alternative to using longitude/latitude props separately. |
longitude | number | — | Longitude coordinate. Use with latitude prop, or use coordinate instead. |
latitude | number | — | Latitude coordinate. Use with longitude prop, or use coordinate instead. |
children | ReactNode | — | Marker subcomponents (MarkerContent, MarkerPopup, MarkerLabel). |
label | string | — | Quick shorthand to add a label without using MarkerLabel component. |
anchor | { x: number; y: number } | { x: 0.5, y: 0.5 } | Anchor point for the marker (0.0 to 1.0). Default is center. |
allowOverlap | boolean | false | Allow marker to overlap with other markers. |
onPress | () => void | — | Callback when marker is pressed. |
MarkerContent
Renders the visual content of a marker. Must be used inside MapMarker. If no children provided, renders a default blue dot marker.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | Custom marker content. Defaults to a blue dot. Can contain any React Native components. |
className | string | — | Additional styles for the marker container. (tailwindcss) |
MarkerPopup
Renders a popup (callout) attached to the marker that opens when the marker is pressed. Must be used inside MapMarker. Uses MapLibre's native Callout component.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | Popup content. Can contain any React Native components. |
title | string | — | Optional title text for the callout. |
className | string | — | Additional styles for the popup container. (tailwindcss) |
MarkerLabel
Renders a text label above or below the marker. Must be used inside MarkerContent.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | Label text content. |
className | string | — | Additional styles for the label container. (tailwindcss) |
classNameText | string | — | Text styles (tailwindcss) |
position | "top" | "bottom" | "top" | Position of the label relative to the marker. |
MapRoute
Renders a polyline on the map connecting coordinate points. Must be used inside Map. Drawn using native MapLibre layers for optimal performance.
| Prop | Type | Default | Description |
|---|---|---|---|
coordinates | Array<[number, number]> | — | Array of [longitude, latitude] coordinate pairs defining the route. |
color | string | "#4285F4" | Line color (CSS color value). |
width | number | 3 | Line width in pixels. |
opacity | number | 0.8 | Line opacity (0 to 1). |
dashArray | [number, number] | — | Dash pattern [dash length, gap length] for dashed lines. |
MapUserLocation
Shows the user's current location on the map with automatic permission handling. Must be used inside Map.
| Prop | Type | Default | Description |
|---|---|---|---|
visible | boolean | true | Show user location on the map. |
showAccuracy | boolean | true | Show accuracy circle around user location. |
showHeading | boolean | false | Show heading arrow indicating device direction. |
animated | boolean | true | Whether the location marker is animated between updates. |
minDisplacement | number | — | Minimum delta in meters for location updates. Helps save battery. |
onPress | () => void | — | Callback when user location marker is pressed. |
autoRequestPermission | boolean | true | Automatically request location permissions if not granted. |
useCurrentPosition
A hook re-exported from MapLibre React Native that provides the user's current location.
import { useCurrentPosition } from "@/components/ui/map";
const position = useCurrentPosition();
// position contains:
// - coords: { longitude, latitude, altitude, accuracy, ... }
// - timestamp: numberLocation Permissions
For manual location permission handling, use expo-location directly. This is the recommended approach and is used internally by MapUserLocation.
import * as Location from "expo-location";
import { useEffect, useState } from "react";
function MyComponent() {
const [hasPermission, setHasPermission] = useState(false);
useEffect(() => {
(async () => {
// Request location permissions
const { status } = await Location.requestForegroundPermissionsAsync();
setHasPermission(status === "granted");
})();
}, []);
// Get current position
const getCurrentLocation = async () => {
if (hasPermission) {
const location = await Location.getCurrentPositionAsync({});
console.log(location.coords.longitude, location.coords.latitude);
}
};
return (
<Map center={[-122.4194, 37.7749]} zoom={12}>
{hasPermission && <MapUserLocation />}
</Map>
);
}Styling
All components accept className string props for additional styling using Tailwind CSS classes (via NativeWind). This allows easy customization of layout, colors, spacing, and more using utility-first CSS directly in your JSX.