Calculate Distance Between Two Lat Long – Free Online Tool

Address by Lat Long








Calculate Distance between two Lat Long

Our tool helps a user to find the distance between two latitudes and longitude. What sets us apart from other tools is that we don't require an internet connection or any sign-in technology. Instead, what our users need is a GPS service on their phone and a place to search for "latitude" and "longitude." Once they enter these values, our tool will show them the distance between these two coordinates using Google Maps APIs. This project was especially challenging because it required building front-end software in JavaScript with no backend servers required to upload data. The entire project was done with HTML, CSS, and JavaScript.

For those unfamiliar with technical concepts, I'll try to be as precise as possible:

All our maps are created using Google Maps API. You can see them on the main page of the website. The map is zoomed out so you can see your current location and its distance from a given point on Earth (the Earth's center). Some controls at the bottom enable you to zoom in and out or pan around the map. These controls also enable an interactive feature where you can drag your location by moving your mouse left or right. The software then does some calculations and updates the information on the screen.

To create a location, a user can either type it in manually or use a map to locate a spot. This is done by clicking on the map and moving the marker to an exact location. Then, it is possible to click on "Save" and add this location to our database. Once this location has been saved, you will see it show up on our map when you type in your desired latitude and longitude values.

To visualize this concept of distance we can look at our formula: distance = (initial_latitude - final_latitude) * 0.0174532925 * cos(initial_longitude - final_longitude).

This formula uses the following:

  • initial_latitude: This represents the latitude of your starting point (the Earth's center).
  • final_latitude: This represents your final destination (where you want to go). Notice that this number is negative. This is because you are traveling in the opposite direction (your starting point is at 0 degrees and your final destination is 180 degrees).
  • initial_longitude: This represents the longitude of your starting point. The degree value here indicates what part of the world you're going through. For instance, if it's a Canadian or Mexican degree, then it means that you're going through Canada or Mexico.

Quick answer

Enter two latitude/longitude pairs; the tool shows the straight-line ('aerial') distance between them in kilometers, plus a driving route on an embedded map.

Key facts

  • Straight-line distance is computed with the Haversine great-circle formula (Earth radius 6371 km)|A driving route and route distance are also shown using Google Maps Directions|Route calculation requires an internet connection to Google's servers|Travel mode for the route can be changed (e.g. driving)|Free to use, no signup required

What is this tool?

This tool calculates the straight-line distance between two GPS coordinates using the mathematically standard Haversine formula, and additionally shows a real driving route between the two points on an embedded map.

How to use it

Enter the latitude and longitude for both locations, then submit. The straight-line distance appears immediately (calculated in your browser), and a driving route with its own distance is drawn on the map below using Google Maps.
  1. Enter the latitude and longitude of the first point.|Enter the latitude and longitude of the second point.|Click the button to calculate.|View the straight-line distance in kilometers, and the driving route drawn on the map below.

Example

Example: entering the coordinates for London (51.5074, -0.1278) and Paris (48.8566, 2.3522) returns a straight-line distance of approximately 344 km, while the driving route distance shown on the map will be longer since it follows actual roads.

How it works

Straight-line distance: d = 2R * asin(sqrt(sin²(Δlat/2) + cos(lat1) * cos(lat2) * sin²(Δlon/2))), with R = 6371 km (Earth's mean radius) -- the standard Haversine formula, computed directly in JavaScript. Driving route: the page separately calls the Google Maps Directions Service with both coordinate pairs, which returns and renders an actual road route and its distance.

Common use cases

Estimating flight or shipping distance between two cities.|Comparing straight-line versus actual driving distance for trip planning.|Checking the distance between two GPS-logged locations.|Educational demonstrations of the Haversine great-circle formula.

Benefits

Free, instant straight-line calculation plus a visual driving route in one tool, without needing a separate mapping application.

Limitations

The Haversine straight-line distance treats the Earth as a perfect sphere, so it is an approximation (accurate to within about 0.5%) rather than an exact geodesic distance; the driving route requires both points to be reachable by road and an active connection to Google's Directions service, and will differ from the straight-line figure since it follows actual roads.

Privacy & your data

The straight-line distance is calculated locally in your browser using JavaScript. The driving-route portion sends both coordinate pairs to Google's Maps Directions service to compute and display a route -- that part is external third-party API processing, not purely local processing.

Frequently asked questions

Why is the driving distance different from the straight-line distance?
The straight-line ('Arial') distance is the direct great-circle path between the two points, while the driving route follows actual roads, which are almost always longer than a straight line.
How accurate is the Haversine formula used here?
The Haversine formula treats the Earth as a perfect sphere, so it's accurate to within about 0.5% of the true geodesic distance -- more than sufficient for most general-purpose distance estimates.
Do I need an internet connection for this tool?
The straight-line distance calculation runs in your browser, but the driving-route map uses Google Maps' Directions service, which requires an internet connection.
Is this tool free to use?
Yes, it's free with no signup required.

Last reviewed: