API Reference

Complete reference for all React Native map components and their props.

Note: This library is built on top of MapLibre React Native. Components use React Native primitives (View, Text, Pressable) and StyleSheet for styling. Refer to the MapLibre React Native API for additional options.

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.

PropTypeDefaultDescription
childrenReactNodeChild components (markers, popups, controls, routes).
center[number, number][0, 0]Initial center coordinate [longitude, latitude].
zoomnumber10Initial 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.
classNamestringContainer style (tailwindcss).
showLoaderbooleantrueShow 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 MapView
  • cameraRef - Ref to MapLibre Camera for programmatic movement
  • isLoaded - Boolean indicating if map is loaded and ready
  • theme - Current theme ("light" or "dark")

MapControls

Renders map control buttons (zoom in/out and locate). Must be used inside Map.

PropTypeDefaultDescription
position"top-left" | "top-right" | "bottom-left" | "bottom-right""bottom-right"Position of the controls on the map.
showZoombooleantrueShow zoom in/out buttons.
showLocatebooleanfalseShow locate button to find user's location. Requires location permissions.
classNamestringAdditional styles for the controls container. (tailwindcss)
onLocate(coords: { longitude: number; latitude: number }) => voidCallback with user coordinates when located.

MapMarker

A container for marker-related components. Provides context for its children and handles marker positioning.

PropTypeDefaultDescription
coordinate[number, number]Marker position as [longitude, latitude]. Alternative to using longitude/latitude props separately.
longitudenumberLongitude coordinate. Use with latitude prop, or use coordinate instead.
latitudenumberLatitude coordinate. Use with longitude prop, or use coordinate instead.
childrenReactNodeMarker subcomponents (MarkerContent, MarkerPopup, MarkerLabel).
labelstringQuick 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.
allowOverlapbooleanfalseAllow marker to overlap with other markers.
onPress() => voidCallback 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.

PropTypeDefaultDescription
childrenReactNodeCustom marker content. Defaults to a blue dot. Can contain any React Native components.
classNamestringAdditional 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.

PropTypeDefaultDescription
childrenReactNodePopup content. Can contain any React Native components.
titlestringOptional title text for the callout.
classNamestringAdditional styles for the popup container. (tailwindcss)

MarkerLabel

Renders a text label above or below the marker. Must be used inside MarkerContent.

PropTypeDefaultDescription
childrenReactNodeLabel text content.
classNamestringAdditional styles for the label container. (tailwindcss)
classNameTextstringText 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.

PropTypeDefaultDescription
coordinatesArray<[number, number]>Array of [longitude, latitude] coordinate pairs defining the route.
colorstring"#4285F4"Line color (CSS color value).
widthnumber3Line width in pixels.
opacitynumber0.8Line 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.

Permissions Required: Make sure you've configured location permissions in your Info.plist (iOS) and AndroidManifest.xml (Android). See the Installation guide.
PropTypeDefaultDescription
visiblebooleantrueShow user location on the map.
showAccuracybooleantrueShow accuracy circle around user location.
showHeadingbooleanfalseShow heading arrow indicating device direction.
animatedbooleantrueWhether the location marker is animated between updates.
minDisplacementnumberMinimum delta in meters for location updates. Helps save battery.
onPress() => voidCallback when user location marker is pressed.
autoRequestPermissionbooleantrueAutomatically 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: number

Location 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.