
Wie berechne ich in PHP die Distanz zwischen zwei Kooardinaten?
In einer Newsgroup habe ich folgende Codeschnipsel gefunden, um die Entfernung (Luftlinie) zwischen zwei Koordinaten zu berechnen. Da mich momentan mit Geodaten und sonstigem Mapping beschäftige, möchte ich euch diesen nützlichen PHP-Code nicht vorenthalten.
Download Code!
/*
Aa => lat1 , Ba =>lon1 , Ca=>lat2 , Da=>lon2
*/
function distance($Aa, $Ba, $Ca, $Da){
$input = array($Aa, $Ba, $Ca, $Da); foreach($input as $name){
if (ereg("[[:alpha:]]",$name)){ echo "You cannot enter letters into this function<br>\n"; }
$dot = ".";
//echo $pos." <br>\n";
if($pos > 3){
echo "The input cannot exceed more than 3 digits left of the decimal<br>\n";
}
}
if($name > 365){
echo "The input cannot exceed 365 degrees <BR>\n";
}
}
$A = $Aa/57.29577951;
$B = $Ba/57.29577951;
$C = $Ca/57.29577951;
$D = $Da/57.29577951;
//convert all to radians: degree/57.29577951
if ($A == $C && $B == $D ){
$dist = 0;
}
$dist = 3963.1* acos(1);// solved a prob I ran into. I haven't fullyanalyzed it yet
}
else{
}
return (round($dist*1.609,2));
}