function getlocations_get_search_distance_sql in Get Locations 7
Same name and namespace in other branches
- 7.2 getlocations.module \getlocations_get_search_distance_sql()
Function
Return value
Returns
File
- ./
getlocations.module, line 6280 - getlocations.module @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL
Code
function getlocations_get_search_distance_sql($latitude, $longitude, $searchdistance, $tbl_alias = '') {
$radius = getlocations_earth_radius($latitude);
$tbl_alias = empty($tbl_alias) ? $tbl_alias : $tbl_alias . '.';
$latfield = $tbl_alias . 'latitude';
$lonfield = $tbl_alias . 'longitude';
// all calcs in mysql
#$sql = "(IFNULL(ACOS((SIN(RADIANS($latitude)) * SIN(RADIANS($latfield)) + (COS(RADIANS($latitude)) * COS(RADIANS($latfield)) * COS(RADIANS($lonfield) - RADIANS($longitude))))), 0.00000) * $radius) BETWEEN 0 AND $searchdistance ";
// some calcs predone in php
$lat = deg2rad($latitude);
$long = deg2rad($longitude);
#$coslong = cos($long);
$coslat = cos($lat);
#$sinlong = sin($long);
$sinlat = sin($lat);
$sql = "(IFNULL(ACOS(({$sinlat} * SIN(RADIANS({$latfield})) + ({$coslat} * COS(RADIANS({$latfield})) * COS(RADIANS({$lonfield}) - {$long} )))), 0.00000) * {$radius})";
if ($searchdistance > 0) {
$sql .= " BETWEEN 0 AND {$searchdistance}";
}
return $sql;
}