from http://www.phpclasses.org/package/7147-PHP-Perform-calculations-with-geographic-coordinates.html pi()) $dLon = $dLon>0 ? -(2*pi()-$dLon) : (2*pi()+$dLon); $brng = atan2($dLon, $dPhi); return (rad2deg($brng)+360) % 360; } public static function mirrorBearing($iBearing, $sAxis='y') { if (strtolower($sAxis) == 'y') { if ($iBearing>180) { $iBearing = ($iBearing - 180) * -1 + 180; } else if ($iBearing<180) { $iBearing = 360 - $iBearing; } } else { if ($iBearing<=180) { $iBearing = 180-$iBearing; } else if ($iBearing>180) { $iBearing = (360 - $iBearing) + 180; } } return $iBearing; } public static function calcLatLong($lat, $long, $distance, $bearing) { // Funny hack for somehow this calculation always came out mirrored over the latitude. $bearing = self::mirrorBearing($bearing); $radian = 180/pi(); $b = $bearing / $radian; $long = $long / $radian; $lat = $lat / $radian; $f = 1/298.257; $e = 0.08181922; $r = self::EARTH_RADIUS * (1 - $e * $e) / pow( (1 - $e*$e * pow(sin($lat),2)), 1.5); $psi = $distance/$r; $phi = pi()/2 - $lat; $arccos = cos($psi) * cos($phi) + sin($psi) * sin($phi) * cos($b); $latA = (pi()/2 - acos($arccos)) * $radian; $arcsin = sin($b) * sin($psi) / sin($phi); $longA = ($long - asin($arcsin)) * $radian; return array('lon' => $longA, 'lat' => $latA); } }