You are here

function getlocations_earth_latitude_range in Get Locations 7

Same name and namespace in other branches
  1. 7.2 getlocations.module \getlocations_earth_latitude_range()

Function

Return value

Returns

5 calls to getlocations_earth_latitude_range()
getlocations_fields_handler_argument_distance::query in modules/getlocations_fields/handlers/getlocations_fields_handler_argument_distance.inc
Set up the query for this argument.
getlocations_fields_handler_filter_distance::query in modules/getlocations_fields/handlers/getlocations_fields_handler_filter_distance.inc
Add this filter to the query.
getlocations_js_settings_do in ./getlocations.module
Function sets up javascript settings
getlocations_leaflet_map_settings_do in modules/getlocations_leaflet/getlocations_leaflet.module
Function
getlocations_search_info_sql in modules/getlocations_search/getlocations_search.module

File

./getlocations.module, line 6227
getlocations.module @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL

Code

function getlocations_earth_latitude_range($latitude, $longitude, $distance) {

  // Estimate the min and max latitudes within $distance of a given location.
  $long = deg2rad($longitude);
  $lat = deg2rad($latitude);
  $radius = getlocations_earth_radius($latitude);
  $angle = $distance / $radius;
  $minlat = $lat - $angle;
  $maxlat = $lat + $angle;
  $rightangle = pi() / 2;
  if ($minlat < -$rightangle) {

    // wrapped around the south pole
    $overshoot = -$minlat - $rightangle;
    $minlat = -$rightangle + $overshoot;
    if ($minlat > $maxlat) {
      $maxlat = $minlat;
    }
    $minlat = -$rightangle;
  }
  if ($maxlat > $rightangle) {

    // wrapped around the north pole
    $overshoot = $maxlat - $rightangle;
    $maxlat = $rightangle - $overshoot;
    if ($maxlat < $minlat) {
      $minlat = $maxlat;
    }
    $maxlat = $rightangle;
  }
  return array(
    rad2deg($minlat),
    rad2deg($maxlat),
  );
}