Lat/Lng Input
Two boxes for one point that takes decimal degrees or degrees-minutes-seconds in either of them, and reports what it could not read instead of substituting a number. Reach for it wherever a person types a place rather than a count: registering a shop, depot, site or asset, drawing a geofence, a collection or drop point for delivery, a survey station or drone waypoint, a wildlife or sensor observation, a property or incident location, and the numeric readout beside a map where somebody nudges a dragged pin. Common asks it answers: "latlng input react", "lat lng input react", "shadcn coordinate input", "latitude longitude input component", "coordinate input react", "dms input react", "decimal degrees to dms javascript", "dms to decimal degrees javascript", "parse 35°41'22"N javascript", "degrees minutes seconds parser js", "convert coordinates react form", "latitude longitude form validation", "validate latitude longitude javascript", "latitude range -90 90 validation", "longitude wrap 180 javascript", "normalize longitude -180 180", "antimeridian 180 or -180", "wrapped longitude 180 becomes -180", "lat lng swapped bug", "geojson coordinates order lat lng", "why are my coordinates reversed", "leaflet latlng vs geojson order", "mapbox coordinates wrong order", "-0 latitude javascript", "Object.is(-0, 0) coordinate", "toFixed loses negative zero", "0 degrees south sign lost", "35°59'60" invalid seconds", "dms rounding 60 seconds carry", "how many decimal places latitude longitude", "5 decimal places latitude meters", "6 decimals gps accuracy", "how precise is 7 decimal places coordinates", "metres per degree longitude latitude", "degree to meters conversion latitude", "cos latitude longitude distance", "store coordinates how many digits", "coordinate input Number('') is 0", "empty latitude posts 0 0", "gulf of guinea 0 0 bug", "paste coordinate from google maps react", "accept both decimal and dms in one input", "geofence coordinate entry form", "store location picker numeric input", "survey station coordinate entry", "drone waypoint latitude longitude form", "asset location form react", "緯度経度 入力 react", "緯度経度 コンポーネント", "度分秒 変換 javascript", "緯度経度 入れ替わり", "経度 180 巻き戻り", "緯度経度 小数 桁数 精度", "緯度経度 バリデーション", "南緯 マイナスゼロ". **The two boxes are not one field with two labels, and all three of their differences are load-bearing.** Latitude stops at ±90 and longitude comes back round the other side; one number of decimals is worth a different distance on each of them; and only one of them has a legitimate value whose sign the language cannot store. Everything below follows from those three. **A latitude past 90 is refused and a longitude past 180 is offered a correction, because only one of them has an unambiguous reading.** 181° is 179°W, the same meridian, so it is folded and the field says so. There is no reading of 95°N that does not also move the longitude 180°, so clamping it to 90 — which is what "saturate the axis" produces — moves the reader's point while reporting success, and it is reported as out of range instead. **The longitude fold has a guard that the formula everybody writes does not.** Measured, `((x + 180) % 360 + 360) % 360 - 180` turns `180` into `-180`: the same meridian, but the other side of the dateline, so a Fiji longitude comes back rewritten. Anything already inside ±180 is handed back untouched and only an out-of-range value is folded, into (-180, 180]. The combination is what makes it dangerous rather than untidy — rounding 179.9999999 to three decimal seconds lands on exactly 180° (measured), so an unguarded wrap takes a point just short of the dateline and puts it across. **0°00'00"S keeps its hemisphere, which costs a separate piece of state and is the only way it survives.** Measured: `String(-0)` is `"0"`, `(-0).toFixed(5)` is `"0.00000"` and `JSON.stringify(-0)` is `0`, while `-0 === 0` is `true` — so a point on the equator in the southern half, or on the prime meridian in the western half, loses its sign the moment anything renders it, and no guard written `< 0` will ever find it again. `Object.is` is the only thing that can see it, the exported `signOf` is built on it, and the hemisphere is a letter on screen rather than a minus sign inferred from the number. **No reading ever says sixty seconds, because the seconds are rounded before the carry rather than after.** Measured, 35.99999997222222° split naively prints `35°59'60.000"` — the seconds come out as 59.9999 and `(59.9995).toFixed(2)` is `"60.00"`. The rounded seconds roll into the minutes and the rounded minutes into the degrees, so the same value prints `36°00'00.000"`. `toFixed` is also not round-half-up (`(1.005).toFixed(2)` is `"1.00"` and `(2.675).toFixed(2)` is `"2.67"`, both measured), which is why the rounding happens in one declared place instead of at each point of display. **It says what a decimal place is worth, and the answer is different on the two axes.** The quoted "111,320 m per degree" is the equatorial longitude degree; the equatorial latitude degree is 110,574.3 m, 746 m shorter, because the meridian is the flatter curve there — so one figure used for both is wrong about one axis everywhere. The longitude degree then falls away with the cosine of the latitude: measured off WGS84, 91,288.2 m at 35°, 55,800.0 m at 60° and 9,734.5 m at 85°. Six decimal places is therefore 11 cm north-south everywhere and 11 cm, 9.1 cm, 5.6 cm or 1 cm east-west depending on where the other box points, and the field prints that sentence rather than leaving the reader to guess. **It will tell you when the digits have stopped being precision.** Five decimals is 1.11 m, where a phone's GPS sits; seven is 1.11 cm, which is survey-grade RTK; eight is 1.1 mm. Nothing in positioning resolves the ninth, so twelve decimal places — 111 nanometres, inside the wavelength of visible light — is not a more exact location, it is the arithmetic residue of whatever converted it. The number is perfectly representable (float64's own step at 180° is 2.8e-14°, about 3 nm); the claim is what is false, and the sentence says so instead of truncating data to make the point. **A swapped pair is flagged and never silently fixed, and the reason is that it can only be found half the time.** GeoJSON writes a point as `[longitude, latitude]` (RFC 7946), the reverse of the order people say out loud, which is why the mistake is so common. A Tokyo pair entered backwards is caught outright, because 139.69 cannot be a latitude. A London pair is not: 51.5072 and -0.1276 are both legal in both boxes, as is every pair whose longitude is inside ±90 — half the planet. Measured over six cities on five continents, four were undetectable. So there is a warning and an explicit Swap control, and no automatic correction that would quietly move the other half of the data. **An empty box and an unreadable box are different answers, and conflating them is the costliest thing this component could do.** `Number("")` is `0` (measured) and 0,0 is a real point in the Gulf of Guinea, so a cleared field that posts it is the default behaviour of the obvious implementation. Empty parses to `null` and junk to `NaN`, and neither is posted. The grammar is strict for the rest of the same reason: measured, `Number("1e3")` is 1000, `Number("0x10")` is 16, `Number("Infinity")` is `Infinity` and `Number(" 35 ")` is 35, and none of those is a latitude — while `35.` and `.5` do pass, because that is what a half-typed decimal looks like. **The characters a pasted coordinate actually carries are normalised, including the one that makes `Number` give up.** `º` U+00BA for the degree sign, `′` and `″` U+2032/U+2033 against the keyboard's `'` and `"`, and `−` U+2212, the mathematical minus, on which `Number("−35")` is `NaN` (measured). A hemisphere letter is read from either end and checked against the axis, so `N` in a longitude box is reported rather than applied; a letter and a `-` that contradict each other (`-35S`) are refused rather than resolved either way; and `35°60'00"` is treated as junk rather than normalised, because normalising it hides that the source was broken. Accessibility and form behaviour: the pair is one `role="group"` with a label, each box separately labelled with an `sr-only` hint naming which way its axis runs, one polite `role="status"` line carries the verdict for the whole group through `aria-describedby` (two live regions race each other and neither gets read), `aria-invalid` follows the actual fault rather than a non-empty box, a folded longitude reads as a note instead of an error, the Swap control is `type="button"` so it cannot submit the form it sits in, and a `name` posts canonical signed decimal degrees through hidden inputs at no fewer than six places however few are displayed — and posts nothing at all when the pair is one it would not stand behind. `parseCoordinate`, `checkCoordinate`, `wrapLongitude`, `toDmsParts`, `fromDmsParts`, `formatDms`, `formatDecimal`, `signOf`, `hemisphereOf`, `looksSwapped`, `metresPerDegree`, `metresForDecimals` and `precisionNote` are exported as plain functions, so the route handler that receives the two strings reaches the same verdict the field showed instead of carrying a second copy of the rules. WGS84 is kept as its two defining numbers with the radii derived, so the figures agree with the ellipsoid rather than with a remembered table. Official shadcn/ui has nothing of the kind and the measurement is not close: fetching every entry in its registry today — 65 listed, 62 fetchable, `code-block`, `questionnaire` and `trace` 404 on both style tracks — and searching all 223,287 bytes, `latitude`, `longitude`, `coordinate`, `coordinates`, `geohash`, `decimalDegrees`, `DMS`, `GeoJSON`, `hemisphere`, `meridian`, `WGS84`, `Object.is` and `toFixed` are every one of them a zero hit; its `input` is a bare text box and `input-group` only puts ornaments either side of one. Within pulld it is the other half of the location pair: `geolocation-button` asks the device where it is and this asks a person where something is, `number-range-input` holds one axis' worth of from-and-to, `unit-input` one value whose unit is part of it, and `masked-input` fixes the shape of a field whose two halves do not have different rules. No dependencies beyond React and your `cn`.
Installation
Requires @pulld in the registries of your components.json (shadcn adds official directory namespaces automatically).
Use with Coding Agent
Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.
Use the "Lat/Lng Input" component (pulld/latlng-input) from its shadcn registry.1. Install it with: npx shadcn@latest add @pulld/latlng-input2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.Files & dependencies
- registry/ui/latlng-input.tsx
Looks similar, elsewhere
There is no screenshot of this item to compare yet.