# Location picker

Set a pickup or delivery point the way a ride app does: the pin stays still and the map moves under it, snapping to the spots a car can actually stop.

> chatcn Pro: needs a Pro license (https://chatcn.dev/pro). Install from the `@chatcn-pro` registry with your license token; setup at https://chatcn.dev/docs/chatcn-pro.

Example: Location picker. Drag the map under the pin. Let go near a suggested spot and it snaps there. Preview: https://chatcn.dev/preview/location-picker-demo

## Installation

```bash
npx shadcn@latest add @chatcn-pro/location-picker
```

## Usage

```tsx
import { LocationPicker } from "@/components/ui/chatcn/pro/location-picker"

<LocationPicker
  title="Pickup point"
  base={district}
  spots={[
    { id: "bakery", name: "Bakery corner", detail: "Step free", x: 240, y: 214 },
    { id: "rank", name: "Taxi rank", detail: "Covered", x: 304, y: 288 },
  ]}
  you={{ x: 178, y: 168, accuracy: 24 }}
  onConfirm={(point, spot) => book(spot ?? point)}
/>
```

The map is the same drawn `MapBase` the list map widget uses, so there are no tiles to load and it matches the theme. Drag it and the pin lifts with its shadow; let go and the map carries on with your flick on a spring, then the pin drops and the place is named below. Land within a thumb of a suggested spot and it snaps there. A tap moves the pin to the point tapped. Spot chips glide to each spot, the locate button goes to `you`, and the zoom buttons or a trackpad pinch zoom; ordinary scrolling stays with the page. Without a spot under the pin the name is the distance from the nearest one, or whatever `describe` returns, which is where a reverse geocoder goes. Set turns the pin green and holds it until Change.

## Examples

### States

Example: States. A pickup already set, and a free pin with no suggested spots. Preview: https://chatcn.dev/preview/location-picker-states

## Props

| Prop | Type | Notes |
| --- | --- | --- |
| `base` | `MapBase` | Water, parks, streets, roads and labels in a 600 by 400 box |
| `spots` | `LocationSpot[]` | `{ id, name, detail?, x, y }` the pin snaps to |
| `you` | `{ x, y, accuracy? }` | The user, with an accuracy ring in meters |
| `defaultCenter`, `defaultZoom` |  | Where it starts. Default the first spot |
| `minZoom`, `maxZoom` | `number` | Default 1 and 3.5 |
| `metersPerUnit` | `number` | For distances. Default 1.5 |
| `describe` | `(point, nearest) => { title, detail? }` | Name the point under the pin |
| `onCenterChange`, `onConfirm` | `(point, spot?) => void` | When the pin rests, and when it is set |
| `height` | `number` | Map height. Default 260 |
| `labels` | `Partial<LocationPickerLabels>` | Every string, for translation |

## Keyboard

| Key | Action |
| --- | --- |
| Arrow keys | Move the map; Shift moves further |
| +, - | Zoom in or out |
| Enter | Set the point |

## Accessibility

- The map is a focusable group described as a map, with the keys in its description.
- The place under the pin is a polite live region, so each stop is announced once.
- Spot chips are toggle buttons; the one under the pin is pressed.

## Motion

The map glides on a critically damped spring that keeps the release velocity. The pin lifts in 200 ms and drops with a small overshoot. Under reduced motion the map jumps and the location ring does not pulse.

Source: https://chatcn.dev/docs/components/location-picker