An A to B distance calculator finds the straight-line distance between two points from their coordinates. Enter each point’s latitude and longitude in decimal degrees; the calculator returns the great-circle distance in kilometres, with miles as a converted equivalent.
Formula
The calculator uses the haversine formula, a standard spherical-Earth method for finding the shortest surface distance between two geographic coordinates. It calculates the central angle between the points, then multiplies that angle by the assumed Earth radius:
a = sin²(Δφ/2) + cos(φ₁) cos(φ₂) sin²(Δλ/2)c = 2 atan2(√a, √(1 − a))d = R × c
- φ₁ and φ₂ are the latitudes of points A and B, converted from degrees to radians.
- λ₁ and λ₂ are their longitudes, also converted to radians.
- Δφ is φ₂ − φ₁, and Δλ is λ₂ − λ₁.
- a is an intermediate value; c is the central angle in radians.
- R is the assumed mean Earth radius, 6,371 kilometres; d is the resulting surface distance in kilometres.
Radians are required by the trigonometric formula, so the calculator converts entered degrees internally. The miles output is the kilometre result multiplied by 0.621371. Both results are rounded to two decimal places.
Worked Example
Using the calculator’s default coordinates, Point A is at latitude 40.7128° and longitude −74.0060°; Point B is at latitude 34.0522° and longitude −118.2437°. These are approximate coordinates for New York City and Los Angeles.
- Convert the coordinate differences to radians: Δφ = (34.0522 − 40.7128) × π/180, approximately −0.1163 radians; Δλ = (−118.2437 − (−74.0060)) × π/180, approximately −0.7720 radians.
- Substitute the differences and Point A and B latitudes into the haversine expression. This gives a central angle of approximately 0.6178 radians.
- Multiply by the assumed Earth radius: 6,371 × 0.6178 ≈ 3,936.38 km.
- Convert to miles: 3,936.38 × 0.621371 ≈ 2,446.00 mi.
Small differences in displayed intermediate values can occur because the calculator retains more precision than the rounded figures shown here.
What “A to B distance” means
“A to B distance” can refer to several different measurements. With latitude and longitude, this calculator reports the shortest distance along an idealized spherical Earth surface, often called great-circle distance. It is not the distance through the Earth, a road journey, or the distance travelled along a particular route.
For two points on a flat map or local drawing, a simpler coordinate distance may be appropriate: √((x₂ − x₁)² + (y₂ − y₁)²). This is Euclidean distance, and its answer uses the same units as the x and y coordinates. Over a small area, a suitable projected map can make that method useful; over large areas, Earth’s curvature matters.
When to use the result
Use great-circle distance for a broad geographic comparison, such as estimating how far apart two cities are “as the crow flies.” It can help compare locations or understand geographic separation, but it does not account for terrain, roads, air corridors, borders, traffic, or access restrictions.
- For a road trip, use a route planner that follows the available road network.
- For a flight itinerary, distinguish direct geographic distance from the actual flight path.
- For land surveying or precise mapping, use an appropriate geodetic method and a suitable coordinate reference system.
- For points on a local diagram, use the diagram’s scale and its own coordinate units rather than entering map coordinates as though they were latitude and longitude.
The displayed distance is a mathematical estimate based on the entered coordinates and a spherical Earth model. It cannot show whether a direct route is physically possible.
Entering coordinates correctly
Latitude tells how far north or south a point is from the equator, ranging from −90° to 90°. Longitude tells how far east or west it is, ranging from −180° to 180°. In this calculator, north and east are positive; south and west are negative. For example, a western longitude such as 74.0060° west must be entered as −74.0060°.
Decimal degrees are not the same as degrees, minutes, and seconds. Convert a coordinate such as 40° 42′ 46″ N into decimal degrees by calculating 40 + 42/60 + 46/3,600, then use a positive sign for north. For south or west, make the converted value negative. Do not append a compass letter to a number already given a sign.
Check that each latitude is paired with its own longitude and that both points use the same coordinate convention. Swapping latitude and longitude can produce a completely different location, even if both numbers fall within the allowed ranges.
Accuracy and common mistakes
The haversine formula treats Earth as a sphere. Earth is slightly flattened at the poles, so a more advanced ellipsoidal geodesic calculation can give a more precise result, particularly when high accuracy is important. For ordinary distance comparisons, the spherical estimate is often a convenient approximation; the number of decimal places shown should not be mistaken for guaranteed real-world accuracy.
- Confusing direct distance with travel distance: routes usually cover more ground than the straight-line surface separation.
- Using the wrong sign: west and south coordinates are negative in this input format.
- Mixing coordinate formats: enter decimal degrees, not unconverted minutes and seconds.
- Rounding too early: keep the original coordinate precision until the calculation is complete.
- Assuming the Earth model is exact: the result depends on the spherical-radius approximation and the accuracy of the coordinates supplied.
For very close points, coordinate quality and rounding can be more important than the difference between distance formulas. For long-distance or technical work, check the coordinates’ source, datum, and required accuracy, and consider a geodesic tool designed for that purpose.
Frequently Asked Questions
How do I calculate the distance between two locations?
Enter the latitude and longitude of each location in decimal degrees. The calculator applies the haversine formula and reports the great-circle distance in kilometres and miles.
Is A to B distance the same as driving distance?
No. This result is the shortest distance over the Earth’s surface between the coordinates. Driving distance follows roads and depends on the route, so it is usually different.
How do I find distance between two points without latitude and longitude?
For points on a flat coordinate grid, use the Euclidean formula √((x₂ − x₁)² + (y₂ − y₁)²). Make sure both coordinate differences use the same units.
Can I enter coordinates in degrees, minutes, and seconds?
Not directly in this calculator. Convert each coordinate to decimal degrees first, then apply the correct positive or negative sign for its direction.
Why does another calculator give a slightly different distance?
Tools can use different Earth models, coordinate precision, or rounding. A spherical haversine result may differ slightly from a more precise ellipsoidal calculation.
Related
Formula used
in lat1 | Point A latitude | ° | 40.7128 | -90 | 90 in lon1 | Point A longitude | ° | -74.0060 | -180 | 180 in lat2 | Point B latitude | ° | 34.0522 | -90 | 90 in lon2 | Point B longitude | ° | -118.2437 | -180 | 180 out km | Straight-line distance | km | 6371 * 2 * atan2(sqrt((sin((lat2-lat1)*pi/180/2))^2 + cos(lat1*pi/180)*cos(lat2*pi/180)*(sin((lon2-lon1)*pi/180/2))^2), sqrt(1-((sin((lat2-lat1)*pi/180/2))^2 + cos(lat1*pi/180)*cos(lat2*pi/180)*(sin((lon2-lon1)*pi/180/2))^2))) | 2 out mi | Straight-line distance | mi | km * 0.621371 | 2
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Immortals Fenyx Rising Co-op, Crossplay and Friends
- AI Inference Near the Device: When It Makes Sense
- Restore Default Settings on a Sons of the Forest Server
- Best Music Streaming Service in India: How to Choose
- How to Clean Gaming Headset Ear Pads Safely
- First Light Trophy List and How to Earn Them