Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function vincenty_distance($fromCoord, $toCoord) {
- /* Vincenty formula for great-circle distance, in kilometers */
- $earthRadius = 6371;
- $fromLat = deg2rad($fromCoord["latitude"]);
- $fromLon = deg2rad($fromCoord["longitude"]);
- $toLat = deg2rad($toCoord["latitude"]);
- $toLon = deg2rad($toCoord["longitude"]);
- $deltaLon = $toLon - $fromLon;
- $a = pow(cos($toLat) * sin($deltaLon), 2) + pow(cos($fromLat) * sin($toLat) - sin($fromLat) * cos($toLat) * cos($deltaLon), 2);
- $b = sin($fromLat) * sin($toLat) + cos($fromLat) * cos($toLat) * cos($deltaLon);
- $angle = atan2(sqrt($a), $b);
- return $angle * $earthRadius;
- }
- if ($_SERVER["HTTP_X_FORWARDED_FOR"] == null) {
- $clientAddr = $_SERVER["REMOTE_ADDR"];
- }
- else {
- $clientAddr = $_SERVER["HTTP_X_FORWARDED_FOR"];
- }
- $serverCoord = geoip_record_by_name($serverAddr);
- $clientCoord = geoip_record_by_name($clientAddr);
- $client_distance = round(vincenty_distance($serverCoord, $clientCoord));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement