GPS Coordinates Validator
Validate GPS coordinates (lat in [-90,90], lng in [-180,180]).
GPS coordinates, WGS84 and the geometry of locating anything on Earth
A pair of GPS coordinates is two numbers — latitude and longitude — that together pinpoint a single position on the surface of the Earth. The numbers only make sense in the context of a datum (a reference ellipsoid that approximates the shape of the planet) and a coordinate system (the units and conventions for expressing them). Modern GPS receivers, web maps and smartphone APIs almost universally use the WGS84 datum (World Geodetic System 1984), defined and maintained by the U.S. National Geospatial-Intelligence Agency and used as the global default since the launch of the GPS constellation in the late 1980s.
In WGS84, latitude ranges from -90 to +90 degrees measured from the Equator, with positive values north and negative values south. Longitude ranges from -180 to +180 degrees measured from the Greenwich meridian, positive east and negative west. The Equator is latitude 0, the Greenwich Prime Meridian is longitude 0, the North Pole sits at +90, the South Pole at -90, and the antimeridian at the date line crosses ±180. São Paulo, Brazil, sits at approximately -23.5505, -46.6333 — south of the Equator, west of Greenwich.
Three notations: DD, DMS and DDM
Coordinates can be expressed in three equivalent formats:
- Decimal Degrees (DD) — a single signed decimal per axis:
-23.5505, -46.6333. Preferred by software and APIs. - Degrees Minutes Seconds (DMS) — used by nautical charts and aviation:
23°33'01.8"S 46°37'59.9"W. - Degrees Decimal Minutes (DDM) — common in marine GPS units:
23°33.030'S 46°37.998'W.
The conversion is purely arithmetic: DD = deg + min/60 + sec/3600, multiplied by -1 when the cardinal letter is S or W. A robust validator must accept any of the three formats, normalize to DD internally, then verify the numeric range.
Precision matters. Each additional decimal place divides the resolution by ten: 5 decimal places give roughly 1 m at the equator, 6 give roughly 10 cm, 7 give roughly 1 cm. Storing latitude/longitude as 64-bit doubles is overkill for street-level accuracy but standard practice; truncating to 4 decimals (≈ 11 m) is enough for delivery addresses and protects user privacy in shared datasets.
Beyond WGS84: SIRGAS 2000 and other regional datums
Brazil maintains its own official datum, SIRGAS 2000 (Sistema de Referência Geocêntrico para as Américas), adopted by IBGE in 2005 and consolidated in 2015 as the only legal datum for cartography in the country. SIRGAS 2000 is aligned to ITRF2000 and is, in practice, indistinguishable from WGS84 at the metre level — but for cadastral or surveying work the legal datum must be the official one. The earlier datum, SAD69 (South American Datum 1969), still appears in legacy maps and can differ from SIRGAS by up to 65 m; coordinates labelled SAD69 must be transformed before they can be safely mixed with modern data.
Globally, the picture is similar: NAD83 in North America, ETRS89 in Europe, GDA2020 in Australia, JGD2011 in Japan. All of them are tightly aligned to the ITRF realization of the date, so for consumer mapping the difference from WGS84 is negligible.
Validation: the regex plus range pattern
A complete GPS validator pipeline does three things in order: parse the input string against a regex permissive enough to accept DD, DMS and DDM; convert to decimal degrees; check that latitude lies in [-90, +90] and longitude in [-180, +180]. Always reject NaN, infinities and out-of-range values explicitly.
function isValidLatLng(lat, lng) {
const a = Number(lat), b = Number(lng)
if (!Number.isFinite(a) || !Number.isFinite(b)) return false
return a >= -90 && a <= 90 && b >= -180 && b <= 180
}
GNSS constellations, accuracy and privacy
GPS is technically only the U.S. constellation. Modern receivers fuse signals from several Global Navigation Satellite Systems: GLONASS (Russia, 24 satellites), Galileo (EU, 28+), BeiDou (China, 35+), QZSS (Japan, regional augmentation) and NavIC (India, regional). Combining constellations is what gets a phone to a 3-5 m fix even between São Paulo skyscrapers. With RTK (Real-Time Kinematics) and a nearby base station, professional receivers reach centimetre accuracy; indoors, devices fall back on Wi-Fi, cell-tower triangulation and Bluetooth beacons.
Privacy: raw EXIF metadata on photos often embeds the exact GPS coordinates where the shot was taken. Posting an unsanitised JPEG to a public site is a textbook OSINT leak — strip GPSLatitude and GPSLongitude EXIF tags before publication, or use a photo manager that does it for you. Delivery apps (iFood, Rappi, Uber), geofencing, sports trackers (Strava heatmaps) and pet trackers all rely on continuous coordinate streams and bring their own surveillance trade-offs.
FAQ
Should I store coordinates in WGS84 or SIRGAS 2000? Web maps, mobile apps and Google/Bing/Apple APIs all expect WGS84. For Brazilian cadastral, surveying or land-registry work, the legally required datum is SIRGAS 2000 — at metre precision the values are practically identical, but legally distinct.
Are latitudes of exactly ±90 valid? Yes. The North Pole is +90.0, the South Pole is -90.0. At those points longitude is undefined (every meridian converges) but the validator should still accept any numeric longitude for them.
How accurate is consumer GPS? Outdoors with clear sky, 3 to 10 m on a modern smartphone using multi-GNSS. Urban canyons and dense canopy can degrade it to 15 to 30 m. Indoors it usually drops to Wi-Fi fingerprinting at 5 to 50 m.
What is the antimeridian and why does it cause bugs? The line at ±180° longitude is where +180 meets -180. Naively computing distance or interpolating across it crosses the wrong way around the planet. Use a geospatial library (turf.js, geolib, PostGIS) for great-circle math instead of subtracting longitudes directly.
What is what3words? A commercial alternative encoding that maps every 3 m × 3 m square on Earth to a unique triplet of dictionary words (e.g. ///filled.count.soap). It is convenient for verbal exchange but is not an open standard and is not a substitute for WGS84 in software.
Related Tools
CPF Validator
Validate Brazilian CPF numbers instantly using the official algorithm. Useful for testing document validation in applications. No data sent to servers.
Batch CPF Validator
Validate a list of CPFs (one per line) and see which are valid and which are not. No data sent to servers.
Batch CNPJ Validator
Validate a list of CNPJs (one per line) with a summary of valid, invalid and total. No data sent to servers.