# React Native Map without native modules (Pro)

> A React Native map for iOS, Android and the web with no native module and no API key to start: raster tiles from any provider, drag, pinch, double tap and wheel zoom, zoom and locate buttons, custom markers, routes, clustering and fit to bounds. Runs in Expo Go and the browser. Part of Patine Pro.

# Map Pro

`MapView` is a slippy map in plain React Native: raster tiles from any provider, one finger to pan, two to pinch, a double tap or the wheel to zoom toward where you point, and zoom and locate buttons. Draw anything at a coordinate with `MapMarker`, and lines with `MapRoute`. There's no native module, so it runs in Expo Go, Snack and the browser, and the same code draws on all three.

Use it for delivery tracking, store finders, trip plans and dashboards. For turn-by-turn navigation, 3D buildings or offline vector maps, use a native SDK such as `react-native-maps` or MapLibre.

```tsx
import { MapMarker, MapRoute, MapView } from '@patine-ui/pro';
```

```tsx live wide
import { View } from 'react-native';
import { Text } from 'patine-ui';
import { MapMarker, MapRoute, MapView } from '@patine-ui/pro';

const STOPS = [
  { id: 'a', name: 'Pike Place', coordinate: { lat: 47.6097, lng: -122.3422 } },
  { id: 'b', name: 'Space Needle', coordinate: { lat: 47.6205, lng: -122.3493 } },
  { id: 'c', name: 'Fremont Troll', coordinate: { lat: 47.651, lng: -122.3473 } },
];

export default function Example() {
  return (
    <MapView fitTo={STOPS.map((s) => s.coordinate)} muted style={{ height: 420 }}>
      <MapRoute coordinates={STOPS.map((s) => s.coordinate)} dashed />
      {STOPS.map((s, i) => (
        <MapMarker key={s.id} coordinate={s.coordinate} accessibilityLabel={s.name}>
          <View style={{ alignItems: 'center' }}>
            <View style={{ paddingHorizontal: 10, paddingVertical: 4, borderRadius: 12, backgroundColor: '#111' }}>
              <Text size="sm" weight="semibold" style={{ color: '#fff' }}>{`${i + 1}. ${s.name}`}</Text>
            </View>
            <View style={{ width: 2, height: 10, backgroundColor: '#111' }} />
          </View>
        </MapMarker>
      ))}
    </MapView>
  );
}
```

## Example: track a delivery

A food order on its way: the route from the restaurant to the door, the courier as a dot on it, and a card with the time left.

```tsx live wide
import { View } from 'react-native';
import { Icon } from '@patine-ui/icons';
import { Avatar, Card, HStack, Text, VStack } from 'patine-ui';
import { MapMarker, MapRoute, MapView } from '@patine-ui/pro';

const ROUTE = [
  { lat: 37.7793, lng: -122.4193 },
  { lat: 37.7775, lng: -122.4166 },
  { lat: 37.7738, lng: -122.4213 },
  { lat: 37.7712, lng: -122.4241 },
  { lat: 37.7694, lng: -122.4268 },
];
const pin = (name: 'store' | 'home') => (
  <View style={{ padding: 6, borderRadius: 16, backgroundColor: '#fff', borderWidth: 1, borderColor: '#e5e5e5' }}>
    <Icon name={name} size="sm" color="primary" />
  </View>
);

export default function Example() {
  return (
    <View style={{ height: 440, width: '100%' }}>
      <MapView fitTo={ROUTE} muted style={{ flex: 1 }}>
        <MapRoute coordinates={ROUTE} />
        <MapMarker coordinate={ROUTE[0]} accessibilityLabel="Lucia's Trattoria">{pin('store')}</MapMarker>
        <MapMarker coordinate={ROUTE[ROUTE.length - 1]} accessibilityLabel="Your address">{pin('home')}</MapMarker>
        <MapMarker coordinate={ROUTE[2]} anchor="center" accessibilityLabel="Courier, 6 minutes away">
          <View style={{ width: 18, height: 18, borderRadius: 9, backgroundColor: '#1F6F64', borderWidth: 3, borderColor: '#fff' }} />
        </MapMarker>
      </MapView>
      <Card style={{ position: 'absolute', left: 12, right: 12, bottom: 12 }}>
        <HStack gap="md" align="center" padding="md">
          <Avatar name="Marco Bianchi" />
          <VStack style={{ flex: 1 }}>
            <Text weight="semibold">Arriving in 6 min</Text>
            <Text size="sm" color="textSecondary">Marco is 1.2 km away · 2 items from Lucia's Trattoria</Text>
          </VStack>
        </HStack>
      </Card>
    </View>
  );
}
```

## Tiles

It opens on OpenStreetMap's own tiles, which are fine for development and light use under the [OSM tile policy](https://operations.osmfoundation.org/policies/tiles/). For a production app, pass a provider's URL template with your key, which also brings dark and satellite styles, and its credit in `attribution`.

```tsx
<MapView
  tiles="https://api.maptiler.com/maps/dataviz/{z}/{x}/{y}.png?key=YOUR_KEY"
  attribution="© MapTiler © OpenStreetMap contributors"
/>
```

`muted` drains the tiles' colour on the web, so markers and routes stand out, as dispatch and analytics maps do.

## Markers and routes

A `MapMarker` is any view; `anchor="bottom"` (the default) sits its bottom on the coordinate, like a pin, and `anchor="center"` centres it, like a dot or a vehicle. Markers keep their size while the map pinches, and only those near the view are drawn. Give a marker `onPress` and an `accessibilityLabel` to make it a button.

`MapRoute` draws a line through coordinates with a white casing, solid or `dashed`.

## Many points

`clusterPoints(points, zoom, radius)` groups points closer than `radius` points on screen, for a store finder with hundreds of pins; draw a cluster as a count and its points as markers. `fitBounds(points, width, height)` gives the centre and zoom that frame them, and `fitTo` does it for you on open.

## Accessibility

- The map has the application role and your `accessibilityLabel`; the zoom and locate buttons are labelled.
- Markers with `onPress` are buttons with their own labels, so a screen reader can reach every place without panning. For long lists, give people a list view too, as the [Dispatch](../pro/dispatch) screen does with its panel.

## Props

### MapView

| Prop | Type | Default |
| --- | --- | --- |
| `initialCenter` | `{ lat, lng }` | London |
| `initialZoom` | `number`, 2 to 19 | `12` |
| `fitTo` | `{ lat, lng }[]`: opens framing these | |
| `onRegionChange` | `({ center, zoom }) => void`, when a gesture settles | |
| `onPress` | `({ lat, lng }) => void`, a tap on the map | |
| `tiles` | `string`, a URL template with `{z}`, `{x}`, `{y}`, `{s}` | OpenStreetMap |
| `attribution` | `string` | OpenStreetMap's |
| `muted` | `boolean` | `false` |
| `controls` | `boolean`: zoom buttons | `true` |
| `onLocate` | `() => void`: shows a locate button | |

### MapMarker

| Prop | Type | Default |
| --- | --- | --- |
| `coordinate` | `{ lat, lng }` | |
| `anchor` | `'bottom'` \| `'center'` | `'bottom'` |
| `onPress` | `() => void` | |
| `accessibilityLabel` | `string` | |

### MapRoute

| Prop | Type | Default |
| --- | --- | --- |
| `coordinates` | `{ lat, lng }[]` | |
| `color` | `string` | The theme's primary |
| `width` | `number` | `4` |
| `dashed` | `boolean` | `false` |

## Related

- [Dispatch](../pro/dispatch): a fleet on a map, ready to rename.
