<?php
const R = 6371; // km
function distance_between_points_rad($lat1, $lng1, $lat2, $lng2){
// latlng in radians
$x = ($lng2-$lng1) * cos(($lat1+$lat2)/2); $y = ($lat2-$lat1);
// return distance in km
return sqrt($x*$x + $y*$y) * R
; }
function get_destination_lat_rad($lat1, $lng1, $d, $brng){
}
function get_destination_lng_rad($lat1, $lng1, $d, $brng){
$lat2 = get_destination_lat_rad($lat1, $lng1, $d, $brng);
}
function get_bounding_box_rad($lat, $lng, $range){
// latlng in radians, $range in km
$latmin = get_destination_lat_rad($lat, $lng, $range, 0);
$latmax = get_destination_lat_rad
($lat, $lng, $range, deg2rad(180)); $lngmax = get_destination_lng_rad
($lat, $lng, $range, deg2rad(90)); $lngmin = get_destination_lng_rad
($lat, $lng, $range, deg2rad(270)); // return approx bounding latlng in radians
return array($latmin, $latmax, $lngmin, $lngmax); }
function distance_between_points_deg($lat1, $lng1, $lat2, $lng2){
// latlng in degrees
// return distance in km
return distance_between_points_rad(
}
function get_bounding_box_deg($lat, $lng, $range){
// latlng in degrees, $range in km
}
// tests
// distance from berlin (52.5200 N, 13.4050 E) to vienna (48.2082 N, 16.3738 E)
echo "Berlin to Vienna " .
distance_between_points_deg(52.5200, 13.4050, 48.2082, 16.3738) . " km \n";
var_dump(get_bounding_box_deg
(52.5200, 13.4050, 0.5));
PD9waHAKCmNvbnN0IFIgPSA2MzcxOyAvLyBrbQoKZnVuY3Rpb24gZGlzdGFuY2VfYmV0d2Vlbl9wb2ludHNfcmFkKCRsYXQxLCAkbG5nMSwgJGxhdDIsICRsbmcyKXsKICAgIC8vIGxhdGxuZyBpbiByYWRpYW5zCiAgICAkeCA9ICgkbG5nMi0kbG5nMSkgKiBjb3MoKCRsYXQxKyRsYXQyKS8yKTsKICAgICR5ID0gKCRsYXQyLSRsYXQxKTsKICAgIC8vIHJldHVybiBkaXN0YW5jZSBpbiBrbQogICAgcmV0dXJuIHNxcnQoJHgqJHggKyAkeSokeSkgKiBSOwp9CgpmdW5jdGlvbiBn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