function earth_latitude_range in Location 7.3
Same name and namespace in other branches
- 5.3 earth.inc \earth_latitude_range()
- 5 earth.inc \earth_latitude_range()
- 6.3 earth.inc \earth_latitude_range()
- 7.5 earth.inc \earth_latitude_range()
- 7.4 earth.inc \earth_latitude_range()
Earth latitude range.
3 calls to earth_latitude_range()
- location_handler_argument_location_proximity::query in handlers/
location_handler_argument_location_proximity.inc - Set up the query for this argument.
- location_search_search_execute in contrib/
location_search/ location_search.module - Implements hook_search_execute().
- location_views_handler_filter_proximity::query in handlers/
location_views_handler_filter_proximity.inc - Add this filter to the query.
File
- ./
earth.inc, line 197 - Trigonometry for calculating geographical distances. All function arguments and return values measure distances in metres and angles in degrees. The ellipsoid model is from the WGS-84 datum. Ka-Ping Yee, 2003-08-11
Code
function earth_latitude_range($longitude, $latitude, $distance) {
// Estimate the min and max latitudes within $distance of a given location.
$long = deg2rad($longitude);
$lat = deg2rad($latitude);
$radius = earth_radius($latitude);
$angle = $distance / $radius;
$minlat = $lat - $angle;
$maxlat = $lat + $angle;
$rightangle = pi() / 2;
// Wrapped around the south pole.
if ($minlat < -$rightangle) {
$overshoot = -$minlat - $rightangle;
$minlat = -$rightangle + $overshoot;
if ($minlat > $maxlat) {
$maxlat = $minlat;
}
$minlat = -$rightangle;
}
// Wrapped around the north pole.
if ($maxlat > $rightangle) {
$overshoot = $maxlat - $rightangle;
$maxlat = $rightangle - $overshoot;
if ($maxlat < $minlat) {
$minlat = $maxlat;
}
$maxlat = $rightangle;
}
return array(
rad2deg($minlat),
rad2deg($maxlat),
);
}