1001Ferramentas
๐Ÿ“Validators

Geographic Coordinate Validator

Accepts coordinates in multiple formats (decimal, DMS, with hemispheres) and validates lat/lon ranges.

Coordinate format detection: DD, DMS, DDM, UTM, MGRS, Plus Code and What3Words

A latitude/longitude pair is just two numbers, but the string used to represent it changes radically depending on the source: a Google Maps URL, an EXIF tag inside a JPEG, a topographic chart, a military situation report and a delivery app each pick a different notation. A coordinate-format validator does something narrower than a generic GPS validator: it inspects the raw string, classifies which of the seven canonical encodings it belongs to, and parses it into a normalised internal form. The seven supported formats โ€” DD, DMS, DDM, UTM, MGRS, Plus Code and What3Words โ€” together cover virtually every coordinate string in the wild.

This tool is not about ranges or datums (that is the job of validador-coordenadas-gps) โ€” it is about parsing the textual envelope first, so that any downstream logic gets a normalised pair regardless of where the string came from.

The seven canonical encodings

  • DD (Decimal Degrees) โ€” signed decimals, comma- or space-separated: -23.5505, -46.6333. Default for APIs.
  • DMS (Degrees Minutes Seconds) โ€” sexagesimal with cardinal letters: 23ยฐ33'01.8"S 46ยฐ37'59.9"W. Used in EXIF GPS tags and nautical charts.
  • DDM (Degrees Decimal Minutes) โ€” hybrid common in marine GPS: 23ยฐ33.030'S 46ยฐ37.998'W.
  • UTM (Universal Transverse Mercator) โ€” zone + easting/northing in metres: 23K 333024 7395060. 60 zones of 6ยฐ width, ideal for surveying and CAD.
  • MGRS (Military Grid Reference System) โ€” NATO grid built on UTM: 23K KP3302473950. Fixed-length, voice-friendly.
  • Plus Code (Open Location Code) โ€” Google's open standard: 8R3R+QF Sรฃo Paulo. Works offline, no API key.
  • What3Words โ€” proprietary 3 m ร— 3 m grid mapped to a triplet of dictionary words: ///filled.count.soap. Licensed API.

Validation regex per format

Auto-detection is a cascade of regex tests, ordered from most specific to most permissive so that the looser DD pattern does not absorb a DMS string that happens to start with digits:

// DD: "-23.5505, -46.6333"
const dd  = /^-?\d{1,3}\.\d+,\s*-?\d{1,3}\.\d+$/

// DMS: 23ยฐ33'01.8"S 46ยฐ37'59.9"W
const dms = /^\d{1,3}ยฐ\d{1,2}'\d{1,2}(\.\d+)?"[NSEW]\s+\d{1,3}ยฐ\d{1,2}'\d{1,2}(\.\d+)?"[NSEW]$/

// UTM: 23K 333024 7395060
const utm = /^\d{1,2}[C-X]\s+\d{6}\s+\d{7}$/

// Plus Code: 8R3R+QF
const olc = /^[23456789CFGHJMPQRVWX]{4,8}\+[23456789CFGHJMPQRVWX]{2,}/

// What3Words: ///word.word.word
const w3w = /^\/{3}[a-z]+\.[a-z]+\.[a-z]+$/

The cardinal heuristic is what makes DMS detection robust โ€” if the string contains ยฐ and an N/S/E/W letter, do not even try the DD regex. UTM is unambiguous because its zone letter follows the digit count. MGRS is harder: a 5-character grid prefix must come right after the UTM zone, then a paired easting/northing of equal length.

DD โ†” DMS conversion and EXIF GPS tags

Conversion between DD and DMS is purely arithmetic โ€” the sign comes from the cardinal letter:

function dmsToDd(deg, min, sec, hemi) {
  const dd = deg + min/60 + sec/3600
  return (hemi === 'S' || hemi === 'W') ? -dd : dd
}

EXIF GPS tags inside JPEG/HEIC photos store coordinates as three RATIONAL values (deg, min, sec) plus a separate GPSLatitudeRef / GPSLongitudeRef byte holding the cardinal โ€” that is essentially DMS without the punctuation. Any photo metadata reader (exifr, ExifTool, Pillow) returns DMS by default; if you need DD for a database column, apply the formula above. Map URLs are inconsistent: Google uses ?q=lat,lng in DD, Apple Maps uses ?ll=lat,lng in DD, Bing uses ?cp=lat~lng with a tilde. KML and GeoJSON are DD-only.

UTM, MGRS and Brazilian datums

UTM divides the world into 60 zones of 6ยฐ longitude; Brazil spans zones 18 to 25, with Sรฃo Paulo in zone 23K. UTM coordinates are linear metres from the zone's central meridian (easting) and from the Equator (northing), which makes distance and area calculations trivial โ€” that is why every CAD project, mining plan and engineering drawing in Brazil uses UTM, not lat/lng. MGRS adds a 100 km ร— 100 km lettered grid square on top, useful when you need to read coordinates over the radio. Datum matters for UTM: the same easting/northing in WGS84 versus SAD69 can shift the point by tens of metres, and the legally valid datum for Brazilian cartography is SIRGAS 2000.

Libraries and tooling

In Node, the coordinate-parser package auto-detects DD, DMS and DDM and normalises to DD; utm handles UTM โ†” DD; mgrs handles MGRS โ†” DD; open-location-code handles Plus Code; turf.js covers great-circle distance, bounding boxes and geodesic interpolation once you have DD. For heavy lifting, PROJ (via proj4js) does arbitrary datum and projection transforms including SIRGAS โ†” WGS84.

FAQ

Which format should I store in the database? DD as two DOUBLE columns, or a PostGIS geography(Point). Convert from DMS/UTM/MGRS at the input boundary. Keeping the original string in a separate column is a good audit trail.

How do I auto-convert between formats? The coordinate-parser npm library auto-detects DD/DMS/DDM and emits DD. For UTM and MGRS, use the dedicated packages above; What3Words requires the proprietary API.

Is What3Words proprietary? Yes. The 3 m ร— 3 m grid algorithm and the wordlist are licensed โ€” you need an API key for production use. Plus Code (Open Location Code) is the open-standard equivalent maintained by Google with a permissive licence.

Why does EXIF store DMS instead of DD? The EXIF spec dates from 1995 and was modelled on existing GPS receiver output, which itself mirrored aeronautical chart notation. DD became the dominant computer-friendly form later; the EXIF spec was never updated for compatibility reasons.

Can a single string mix two formats? No โ€” a well-formed coordinate string belongs to exactly one of the seven encodings. If detection returns multiple matches, the input is ambiguous and should be rejected for human review.

Related Tools