Note that there are some explanatory texts on larger screens.

plurals
  1. PODistance between lat/long points using the haversine formula
    text
    copied!<p>I am trying to find the distance between two longitude and latitude points. I am trying ot use the <a href="http://en.wikipedia.org/wiki/Great-circle_distance" rel="nofollow noreferrer">great circle distance</a>. This is the formula: <img src="https://i.stack.imgur.com/3UhsO.png" alt="alt text"></p> <p>I am not sure why but my program is not working. This is the result I am getting: </p> <pre><code>Change Angle: 0.00016244370761414 Earth Radius: 6371 RESULTS: Correct Distance: 24.883 km Computed Distance: 1.0349288612097 </code></pre> <p>Source:</p> <pre><code>$latStart = 44.638; $longStart = -63.587; $latFinish = 44.644; $longFinish = -63.597; # Convert Input to Radians $latStart = deg2Rad($latStart); $longStart = deg2Rad($longStart); $latFinish = deg2Rad($latFinish); $longFinish = deg2Rad($longFinish); # Because the Earth is not perfectly spherical, no single value serves as its # natural radius. Distances from points on the surface to the center range from # 6,353 km to 6,384 km (≈3,947–3,968 mi). Several different ways of modeling the # Earth as a sphere each yield a convenient mean radius of 6371 km (≈3,959 mi). # http://en.wikipedia.org/wiki/Earth_radius $earthRadius = 6371; # difference in Long/Lat $latChange = $latFinish - $latStart; $longChange = $longFinish - $longStart; # haversine formula # numerically stable for small distances # http://en.wikipedia.org/wiki/Great-circle_distance $changeAngle = 2 * asin( sqrt( pow(sin($latChange/2),2) + cos($latStart) * cos($latFinish) * pow(sin($longChange/2),2) ) ); echo "Change Angle: $changeAngle\n"; echo "Earth Radius: $earthRadius\n"; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload