Overview
You would like to know whether the distance calculation in the nearest location search results are plotting accurately. You looked for nearby locations from Dumfries, UK and saw that the results are all equidistant from the reference point.
Information
The distance calculation on the locator for these Dumfries, UK locations is accurate. It uses the Haversine formula to determine the distance calculation.
- The Agent Locator search is using Google Geocoding API to calculate the coordinates for the logical center of Dumfries, UK. (Calculated as Latitude / Longitude)
- Dumfries, UK
- Latitude: 55.070859 / Longitude: -3.60512
- Then it is plotting a direct point-to-point distance calculation to the coordinates that we are receiving for each of the locations and displaying them closest first.
- For example the first location and closest location in the search results:
- Point A
- Coordinates: Latitude: 54.702355, Longitude: -3.276575
- Distances on a map are calculated using the Haversine formula: The haversine formula determines the great-circle distance between two points on a sphere given their longitudes and latitudes.
- The point-to-point distance between these 2 sets of coordinates is 46.05 km based on this formula. The driving distance will be slightly even more than the calculated number (Around 54 km).
- Important in navigation, it is a special case of a more general formula in spherical trigonometry, the law of haversines, that relates the sides and angles of spherical triangles.
Haversine formula: |
a = sin²(Δφ/2) + cos φ1 ⋅ cos φ2 ⋅ sin²(Δλ/2) |
c = 2 ⋅ atan2( √a, √(1−a) ) |
|
d = R ⋅ c |
|
where |
φ is latitude, λ is longitude, R is earth’s radius (mean radius = 6,371km); note that angles need to be in radians to pass to trig functions! |
Comments
0 comments
Please sign in to leave a comment.