伴随球面定律的不准确...特别是沿纬度?

I have a strange problem using the Cosine formula in my PHP application..

function CalculateDistanceCosine($decA, $decB)
{
    $lon1 = $decA[0]; //This would be equal to point A's longitude, and so on..
    $lat1 = $decA[1]; 
    $lon2 = $decB[0];   
    $lat2 = $decB[1];

    //echo $lon1." ".$lat1."<br/>";
    //echo $lon2." ".$lat2."<br/>";

    $distance  = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($lon2-$lon1));
    $distance  = acos($distance);
    $distance  = rad2deg($distance);
    $distance  = $distance * 60 * 1.1515;
    $distance  = round($distance, 4);

    return $distance;   
}

My input into this would be something like this:

45.468055555556 -73.741388888889 //- The coordinates for Montreal International Airport
28.428888888889 -81.315833333333 //- Orlando International Airport

However, upon using it, I get wild mistakes.. i.e, "The distance from Montreal to Orlando is 576 KM -- very wrong."

What's interesting is that it is very accurate along the longitude axis. For example, if I gave an input of:

50 -73.741388888889 
50 -81.315833333333 

The error is now only about 50KM, very acceptable.

In other words, why is it neglecting latitudinal differences?

I've tried the Harvesine formula with similar results unfortunately.

I believe your main problem is that you're getting latitude confused with longitude. You've not shown us the code that's wrong, but bear in mind that in your arrays, you would need the longitude first, followed by the latitude, for your function to work. In the example you've given, you've listed the latitude first, followed by the longitude.

Your code would certainly work out the distance between those two points as written as 576 (in units I'll mention in a minute), but those points aren't actually where you think they are :) Try changing your function as follows:

$lat1 = $decA[0]; //This would be equal to point A's *latitude*, and so on..
$lon1 = $decA[1]; 
$lat2 = $decB[0];   
$lon2 = $decB[1];

...or just pass in the values in the expected order.

Also, I don't recognise your distance multiplier, but it looks like you might be calculating your result in miles, not kilometres. For kilometres, try:

$distance  = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($lon2-$lon1));
$distance  = acos($distance);
$distance  = $distance * 6372.8;
$distance  = round($distance, 4);

(It's only skipping the conversion back to degrees and the multiplier that's changed, the basic formula remains the same.)

Given the above changes, your distance works out at around 2,008 kilometres. Is that about right? I'm afraid I've never visited Montreal, Orlando, or anywhere in between...

Did you took a look here: Using the Cosine law to calculate distance between 2 points in Objective C?? After the distance calculation with the cosine law the distance doesn't get convert back to degree and it is multiply with the earth radius. IMO you forgot the earth radius.