Coordinate Input

Reads coordinates in any common format and catches swapped or sign-flipped values, so a pin doesn't land on the wrong continent.

StopsPin lands on the wrong continent

Installation

pnpm dlx shadcn@latest add https://bollard-ui.vercel.app/r/coordinate-input.json

The files land in your project. They're yours to edit.

Usage

coordinate-input-usage.tsx
import { CoordinateInput } from "@/components/ui/coordinate-input"

<CoordinateInput label="Warehouse location" expectedArea={pune} defaultValue="73.8567, 18.5204" />

What it catches

  • Latitude and longitude swapped
  • West or south signs flipped, compared with the expected area
  • 0, 0 left as a default
  • Map links pasted in, using the pin rather than the map centre
  • DMS and decimal formats, read back as one point

Props

CoordinateInput props
PropTypeDefault
label

Visible label.

string"Coordinates"
value

Controlled text, as typed or pasted.

string—
defaultValue

Initial text when uncontrolled.

string""
onValueChange

Called with the text and the point, or null while it can't be read or is out of range.

(text: string, point: LatLon | null) => void—
expectedArea

Where points should usually be. Enables the swapped and flipped-sign checks.

LatLon & { radiusKm: number; name?: string }—
hint

Helper text shown while the field is empty.

string—
messages

Override any of the default messages.

Partial<typeof COORDINATE_MESSAGES>—

* required. Also accepts the native props of <input> (className, aria-*, data-*…), passed through to it.

Accessibility

  • Visible <label>; aria-invalid and aria-describedby to an aria-live="polite" status
  • Fix buttons have visible text
  • Icons are aria-hidden; the point is read back in text

Only what the source does. Test with your own screen reader and content before shipping.

Limitations

  • Sign and swap checks need an expectedArea to compare against
  • Assumes WGS 84 latitude/longitude; projected coordinates are not supported
  • The OpenStreetMap link opens an external site

What it stops

Pin lands on the wrong continent

Also known as

latitude longitude · lat lng · coordinates · gps · google maps link · dms · location · geo

Field type

Dependencies

Pairs well with