Skip to content Skip to sidebar Skip to footer

I Cannot Get The Same Accuracy As Google Maps When It Comes To Distance?

I am developing an app which calculate the distance between 2 points. I cannot use the Google Maps API. I have found the coordinates for each of the markers in the map below. I am

Solution 1:

If I have correctly entered your start and end points, this implementation of the haversine formula (which I have tested in the real world) produces a distance of 895m (straight line).

var lt = 51.472447;
var lt1 = 51.465097;
var ln = -3.176151;
var ln1 = -3.170893;
var dLat = (lt - lt1) * Math.PI / 180;
var dLon = (ln - ln1) * Math.PI / 180;
var a = 0.5 - Math.cos(dLat) / 2 + Math.cos(lt1 * Math.PI / 180) * Math.cos(lt * Math.PI / 180) * (1 - Math.cos(dLon)) / 2;
d = Math.round(6371000 * 2 * Math.asin(Math.sqrt(a)));

$('#distance').html(d);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="distance"></div>

Post a Comment for "I Cannot Get The Same Accuracy As Google Maps When It Comes To Distance?"