Every point on Earth can be described by two numbers: latitude and longitude. These coordinates are the foundation of all digital mapping, from Google Maps to GPS navigation to the map tool on this site. Understanding how they work helps you work with location data effectively.

Latitude and Longitude

Latitude measures north-south position, ranging from -90° (South Pole) to +90° (North Pole). The equator is 0°. Kolkata, India is at approximately 22.57°N latitude.

Longitude measures east-west position, ranging from -180° to +180°. The Prime Meridian (0°) passes through Greenwich, London. Kolkata is at approximately 88.36°E longitude.

Advertisement

Together, a latitude-longitude pair uniquely identifies any point on Earth's surface. Kolkata is at (22.5726, 88.3639).

Decimal Degrees vs Degrees-Minutes-Seconds

Coordinates can be expressed in two formats:

Always use decimal degrees in code. Most APIs, databases, and libraries expect this format.

The Problem: Map Projections

The Earth is a sphere (roughly), but screens and paper are flat. Converting a sphere to a flat surface requires a map projection, and every projection distorts something — area, shape, distance, or direction. There's no perfect solution; you choose the projection that preserves what matters most for your use case.

Web Mercator (EPSG:3857)

The projection used by Google Maps, OpenStreetMap, and virtually every web mapping library. It preserves angles and shapes locally (making it good for navigation) but massively distorts area near the poles. Greenland appears roughly the same size as Africa, when Africa is actually 14x larger.

Web Mercator is fine for most web mapping applications. Just be aware that the visual size of countries is misleading at high latitudes.

WGS 84 (EPSG:4326)

The coordinate reference system used by GPS. Latitude and longitude in decimal degrees. This is what you get from navigator.geolocation in the browser and from most location APIs.

When working with web maps, you often need to convert between WGS 84 (lat/lon) and Web Mercator (x/y in metres). Libraries like Leaflet and Turf.js handle this automatically.

Working with Coordinates in Code

Getting the User's Location

navigator.geolocation.getCurrentPosition(pos => {
  const lat = pos.coords.latitude;
  const lon = pos.coords.longitude;
  console.log(`You are at ${lat}, ${lon}`);
});

This prompts the user for permission and returns WGS 84 coordinates.

Calculating Distance Between Points

The Haversine formula calculates the great-circle distance between two points on a sphere:

function haversine(lat1, lon1, lat2, lon2) {
  const R = 6371; // Earth radius in km
  const dLat = (lat2 - lat1) * Math.PI / 180;
  const dLon = (lon2 - lon1) * Math.PI / 180;
  const a = Math.sin(dLat/2)**2 +
    Math.cos(lat1 * Math.PI / 180) *
    Math.cos(lat2 * Math.PI / 180) *
    Math.sin(dLon/2)**2;
  return R * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
}

For most applications, this gives sufficiently accurate results. For surveying-grade accuracy, use the Vincenty formula or a geodesy library.

Common Coordinate Mistakes

The map tool on this site uses Leaflet.js to render interactive maps. You can search for locations, drop markers, measure distances, and export coordinates. Everything runs in your browser with OpenStreetMap tiles — no API key required.