CHAPTER 03
Coordinate systems: latitude and longitude
Latitude and longitude explained — decimal vs DMS notation, WGS84 and EPSG:4326, datum shifts, and how big a degree actually is in metres.
Before you can do any map math, you need a precise model of where a point is on Earth. Latitude and longitude are the coordinate systems every developer uses: a two-number address agreed on internationally and supported by virtually every GPS receiver, mapping API, and spatial database in existence.
The basics
- Latitude (φ): North-south, from −90° (South Pole) to +90° (North Pole). The equator is 0°.
- Longitude (λ): East-west, from −180° to +180°. The prime meridian (Greenwich) is 0°.
A point is written as (lat, lon) in most APIs (Google, Apple), but as [lon, lat] in GeoJSON (because GeoJSON follows the (x, y) convention). This trips up every developer at least once.
// Google Maps style:
const point = { lat: 31.5204, lng: 74.3587 }; // Lahore
// GeoJSON style:
const point = [74.3587, 31.5204]; // [lon, lat]
The reason GeoJSON uses [lon, lat] is that longitude is the east-west axis — analogous to x in a standard Cartesian plane — and latitude is north-south, analogous to y. Cartographers conventionally write (x, y) first, so GeoJSON follows that order. Most web APIs flip this to (lat, lon) because humans think of location as "how far north/south, then how far east/west."
Decimal degrees vs DMS
Two notations exist for the same coordinate. If you've used GPS units or topographic maps before, you've seen both.
- Decimal degrees (DD):
31.5204°— the format every API and database uses - Degrees-Minutes-Seconds (DMS):
31° 31' 13.4"— the traditional format for navigation charts
Conversion:
Q: Convert
31° 31' 13.44"to decimal degrees.
Always work in decimal degrees in code. DMS is a display format — convert on input, convert back on output if needed for human readability.
How big is a degree?
This is one of the most useful intuitions you can have. Drag the slider to see how 1° of longitude shrinks as you move toward the poles.
How big is 1° of longitude at latitude φ?
1° latitude
111.20 km
constant everywhere
1° longitude at 45°
78.63 km
× cos(45°)
Relative width of 1° longitude
70.7% of equatorial width
| Quantity | Value |
|---|---|
| 1° latitude | ≈ 111.32 km (everywhere) |
| 1° longitude | ≈ 111.32 km × cos(latitude) |
Latitude lines are evenly spaced. Longitude lines converge at the poles. So at 60° N, one degree of longitude is only ~55.7 km.
The convergence of longitude lines is why you can't use simple Pythagorean math to compute distances between two lat/lon points — the grid is not uniform. A 1° × 1° box near the equator is nearly square; the same box near the poles is a very thin sliver.
Formula for the length of 1° of longitude at latitude φ:
Q: How far apart are two points at the same latitude (51.5° N, London) but 1° apart in longitude?
Datums (briefly)
A datum defines where (0, 0) sits and the shape of the reference ellipsoid. The Earth is not a perfect sphere — it bulges at the equator and flattens at the poles. A datum specifies the exact ellipsoid used, including its semi-major axis (equatorial radius) and flattening factor.
The dominant datum today is WGS84, used by GPS. Older maps may use NAD27, NAD83, OSGB36, etc. Coordinates can shift by tens to hundreds of meters between datums, so always know which one your data uses. A GPS coordinate in WGS84 can be 50–100 m away from the "same" location in a legacy national datum — enough to place a marker on the wrong building.
EPSG codes are standard identifiers:
EPSG:4326— WGS84 lat/lon (degrees)EPSG:3857— Web Mercator (meters, used by Google/Bing/OSM tiles)
References
2 sources- [1]
International Organization for Standardization (2008).
“ISO 6709: Standard Representation of Geographic Point Location by Coordinates.”
ISO Standard
Defines the order and format of geographic coordinates — critical for avoiding lat/lon swap bugs.
- [2]
Open Geospatial Consortium (2005).
“OpenGIS Web Map Service (WMS) Implementation Specification.”
Formalises EPSG codes and CRS identifiers as used by web mapping services.
Related chapters
- Map projections — flattening the globe — what happens to lat/lon on a flat map
- Coordinate transforms — converting between CRS — moving between coordinate reference systems
- Distance on a sphere — Haversine and friends — the first calculation you'll do with lat/lon