+--------------------------------------------------------------------+
| CiviCRM version 4.6 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014 |
+ | Copyright CiviCRM LLC (c) 2004-2015 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
-*/
+ */
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
* $Id$
*
*/
* 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
-
* earth_radius_semimajor = 6378137.0;
* earth_flattening = 1/298.257223563;
* earth_radius_semiminor = $earth_radius_semimajor * (1 - $earth_flattening);
* earth_eccentricity_sq = 2*$earth_flattening - pow($earth_flattening, 2);
-
* This library is an implementation of UCB CS graduate student, Ka-Ping Yee (http://www.zesty.ca).
* This version has been taken from Drupal's location module: http://drupal.org/project/location
- **/
+ */
static protected $_earthFlattening;
static protected $_earthRadiusSemiMinor;
}
}
- /**
+ /*
* Latitudes in all of U. S.: from -7.2 (American Samoa) to 70.5 (Alaska).
* Latitudes in continental U. S.: from 24.6 (Florida) to 49.0 (Washington).
* Average latitude of all U. S. zipcodes: 37.9.
*/
- /*
- /**
- * Estimate the Earth's radius at a given latitude.
- * Default to an approximate average radius for the United States.
- */
-
+ /**
+ * Estimate the Earth's radius at a given latitude.
+ * Default to an approximate average radius for the United States.
+ *
+ * @param float $latitude
+ * @return float
+ */
public static function earthRadius($latitude) {
$lat = deg2rad($latitude);
/**
* Convert longitude and latitude to earth-centered earth-fixed coordinates.
* X axis is 0 long, 0 lat; Y axis is 90 deg E; Z axis is north pole.
+ *
+ * @param float $longitude
+ * @param float $latitude
+ * @param float $height
+ *
+ * @return array
*/
public static function earthXYZ($longitude, $latitude, $height = 0) {
$long = deg2rad($longitude);
$lat = deg2rad($latitude);
$cosLong = cos($long);
- $cosLat = cos($lat);
+ $cosLat = cos($lat);
$sinLong = sin($long);
- $sinLat = sin($lat);
+ $sinLat = sin($lat);
$radius = self::$_earthRadiusSemiMajor / sqrt(1 - self::$_earthEccentricitySQ * $sinLat * $sinLat);
/**
* Convert a given angle to earth-surface distance.
+ *
+ * @param float $angle
+ * @param float $latitude
+ * @return float
*/
public static function earthArcLength($angle, $latitude) {
return deg2rad($angle) * self::earthRadius($latitude);
/**
* Estimate the min and max longitudes within $distance of a given location.
+ *
+ * @param float $longitude
+ * @param float $latitude
+ * @param float $distance
+ * @return array
*/
public static function earthLongitudeRange($longitude, $latitude, $distance) {
- $long = deg2rad($longitude);
- $lat = deg2rad($latitude);
+ $long = deg2rad($longitude);
+ $lat = deg2rad($latitude);
$radius = self::earthRadius($latitude);
- $angle = $distance / $radius;
- $diff = asin(sin($angle) / cos($lat));
+ $angle = $distance / $radius;
+ $diff = asin(sin($angle) / cos($lat));
$minLong = $long - $diff;
$maxLong = $long + $diff;
- if ($minLong < - pi()) {
+ if ($minLong < -pi()) {
$minLong = $minLong + pi() * 2;
}
$maxLong = $maxLong - pi() * 2;
}
- return array(rad2deg($minLong),
+ return array(
+ rad2deg($minLong),
rad2deg($maxLong),
);
}
/**
* Estimate the min and max latitudes within $distance of a given location.
+ *
+ * @param float $longitude
+ * @param float $latitude
+ * @param float $distance
+ * @return array
*/
public static function earthLatitudeRange($longitude, $latitude, $distance) {
- $long = deg2rad($longitude);
- $lat = deg2rad($latitude);
+ $long = deg2rad($longitude);
+ $lat = deg2rad($latitude);
$radius = self::earthRadius($latitude);
- $angle = $distance / $radius;
- $minLat = $lat - $angle;
- $maxLat = $lat + $angle;
+ $angle = $distance / $radius;
+ $minLat = $lat - $angle;
+ $maxLat = $lat + $angle;
$rightangle = pi() / 2.0;
// wrapped around the south pole
- if ($minLat < - $rightangle) {
+ if ($minLat < -$rightangle) {
$overshoot = -$minLat - $rightangle;
$minLat = -$rightangle + $overshoot;
if ($minLat > $maxLat) {
$maxLat = $rightangle;
}
- return array(rad2deg($minLat),
+ return array(
+ rad2deg($minLat),
rad2deg($maxLat),
);
}
/**
- * @param $latitude
- * @param $longitude
- * @param $distance
+ * @param float $latitude
+ * @param float $longitude
+ * @param float $distance
* @param string $tablePrefix
*
* @return string
$params = array();
$clause = array();
- list($minLongitude, $maxLongitude) =
- self::earthLongitudeRange($longitude,
- $latitude,
- $distance
- );
- list($minLatitude, $maxLatitude) =
- self::earthLatitudeRange(
- $longitude,
- $latitude,
- $distance
- );
+ list($minLongitude, $maxLongitude) = self::earthLongitudeRange($longitude, $latitude, $distance);
+ list($minLatitude, $maxLatitude) = self::earthLatitudeRange($longitude, $latitude, $distance);
// DONT consider NAN values (which is returned by rad2deg php function)
// for checking BETWEEN geo_code's criteria as it throws obvious 'NAN' field not found DB: Error
/**
* @param $query
- * @param $values
+ * @param array $values
*
* @throws Exception
+ * @return void
*/
public static function process(&$query, &$values) {
list($name, $op, $distance, $grouping, $wildcard) = $values;
}
if (empty($proximityAddress)) {
- return;
+ return NULL;
}
if (isset($proximityAddress['state_province_id'])) {
}
}
- if (isset($proximityAddress['country_id'])) {
+ if (!empty($proximityAddress['country_id'])) {
$proximityAddress['country'] = CRM_Core_PseudoConstant::country($proximityAddress['country_id']);
$qill[] = $proximityAddress['country'];
}
-
if (
isset($proximityAddress['distance_unit']) &&
$proximityAddress['distance_unit'] == 'miles'
$qill = ts('Proximity search to a distance of %1 from %2',
array(
1 => $qillUnits,
- 2 => implode(', ', $qill)
+ 2 => implode(', ', $qill),
)
);
$query->_tables['civicrm_address'] = $query->_whereTables['civicrm_address'] = 1;
- require_once (str_replace('_', DIRECTORY_SEPARATOR, $fnName) . '.php');
+ require_once str_replace('_', DIRECTORY_SEPARATOR, $fnName) . '.php';
$fnName::format($proximityAddress);
if (
!is_numeric(CRM_Utils_Array::value('geo_code_1', $proximityAddress)) ||
$qill .= ': ' . ts('We could not geocode the destination address.');
$query->_qill[$grouping][] = $qill;
$query->_where[$grouping][] = ' (0) ';
- return;
+ return NULL;
}
$query->_qill[$grouping][] = $qill;
$distance
);
- return;
+ return NULL;
}
/**
- * @param $input
+ * @param array $input
+ * retun void
+ *
+ * @return null
*/
public static function fixInputParams(&$input) {
foreach ($input as $param) {
}
}
}
- return;
+ return NULL;
}
}
}
+
}