Код: Выделить всё
/**
* Get NE & SW coordinates around a point
*
* @param $lat float latitude of origin pt
* @param $lng float longitude of origin pt
* @param $distance int radius in km
*
*/
function getBoundsCoords($latitude, $longitude, $distance) {
$radius = 6378.1;
$neLat = rad2deg(asin(sin(deg2rad($latitude)) * cos($distance / $radius) + cos(deg2rad($latitude)) * sin($distance / $radius) * cos(deg2rad(0))));
$swLat = rad2deg(asin(sin(deg2rad($latitude)) * cos($distance / $radius) + cos(deg2rad($latitude)) * sin($distance / $radius) * cos(deg2rad(180))));
$neLng = rad2deg(deg2rad($longitude) + atan2(sin(deg2rad(90)) * sin($distance / $radius) * cos(deg2rad($latitude)), cos($distance / $radius) - sin(deg2rad($latitude)) * sin(deg2rad($neLat))));
$swLng = rad2deg(deg2rad($longitude) + atan2(sin(deg2rad(270)) * sin($distance / $radius) * cos(deg2rad($latitude)), cos($distance / $radius) - sin(deg2rad($latitude)) * sin(deg2rad($neLat))));
return array(
'ne' => array(
'lat' => $neLat,
'lng' => $neLng
),
'sw' => array(
'lat' => $swLat,
'lng' => $swLng
)
);
}
Код: Выделить всё
function getCoordsFromBounds($coordsNeSw) {
return array(
'lat' => ($coordsNeSw['ne']['lat'] + $coordsNeSw['sw']['lat']) / 2,
'lng' => ($coordsNeSw['ne']['lng'] + $coordsNeSw['sw']['lng']) / 2,
'radius' => "??????"
);
}
Подробнее здесь: https://stackoverflow.com/questions/331 ... ne-sw-area
Мобильная версия