function earth_longitude_range in Location 7.3
Same name and namespace in other branches
- 5.3 earth.inc \earth_longitude_range()
- 5 earth.inc \earth_longitude_range()
- 6.3 earth.inc \earth_longitude_range()
- 7.5 earth.inc \earth_longitude_range()
- 7.4 earth.inc \earth_longitude_range()
Earth longitude range.
@todo This function uses earth_asin_safe so is not accurate for all possible parameter combinations. This means this function doesn't work properly for high distance values. This function needs to be re-written to work properly for larger distance values.
See also
3 calls to earth_longitude_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 169 - 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_longitude_range($longitude, $latitude, $distance) {
// Estimate the min and max longitudes within $distance of a given location.
$long = deg2rad($longitude);
$lat = deg2rad($latitude);
$radius = earth_radius($latitude) * cos($lat);
if ($radius > 0) {
$angle = abs($distance / $radius);
$angle = min($angle, pi());
}
else {
$angle = pi();
}
$minlong = $long - $angle;
$maxlong = $long + $angle;
if ($minlong < -pi()) {
$minlong = $minlong + pi() * 2;
}
if ($maxlong > pi()) {
$maxlong = $maxlong - pi() * 2;
}
return array(
rad2deg($minlong),
rad2deg($maxlong),
);
}