MapMath

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.

3 min readfree

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

optional — skip if familiarrefresher

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:

DD=degrees+minutes60+seconds3600DD = \text{degrees} + \frac{\text{minutes}}{60} + \frac{\text{seconds}}{3600}

Q: Convert 31° 31' 13.44" to decimal degrees.

DD=31+31/60+13.44/3600=31+0.51667+0.0037331.5204°DD = 31 + 31/60 + 13.44/3600 = 31 + 0.51667 + 0.00373 \approx 31.5204°

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 φ?

φ = 45°90°N90°S

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

QuantityValue
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 φ:

length=π180Rcos(φ)\text{length} = \frac{\pi}{180} \cdot R \cdot \cos(\varphi)

Q: How far apart are two points at the same latitude (51.5° N, London) but 1° apart in longitude?

length=π1806,371,008.8cos(51.5°π/180)\text{length} = \frac{\pi}{180} \cdot 6{,}371{,}008.8 \cdot \cos(51.5° \cdot \pi/180) =111,195×cos(0.8988)=111,195×0.622569,222 m69.2 km= 111{,}195 \times \cos(0.8988) = 111{,}195 \times 0.6225 \approx 69{,}222 \text{ m} \approx 69.2 \text{ km}

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. [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. [2]

    Open Geospatial Consortium (2005).

    OpenGIS Web Map Service (WMS) Implementation Specification.”

    OGC Document 06-042

    Formalises EPSG codes and CRS identifiers as used by web mapping services.