You are here

function getlocations_earth_distance in Get Locations 7

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

Parameters

float $longitude1:

float $latitude1:

float $longitude2:

float $latitude2:

Return value

Returns distance in meters

1 call to getlocations_earth_distance()
getlocations_distance_between in ./getlocations.module
Given two points in lat/lon form, returns the distance between them.

File

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

Code

function getlocations_earth_distance($longitude1, $latitude1, $longitude2, $latitude2) {
  $longitude1 = floatval($longitude1);
  $latitude1 = floatval($latitude1);
  $longitude2 = floatval($longitude2);
  $latitude2 = floatval($latitude2);

  // Estimate the earth-surface distance between two locations.
  $long1 = deg2rad($longitude1);
  $lat1 = deg2rad($latitude1);
  $long2 = deg2rad($longitude2);
  $lat2 = deg2rad($latitude2);
  $radius = getlocations_earth_radius(($latitude1 + $latitude2) / 2);
  $cosangle = cos($lat1) * cos($lat2) * (cos($long1) * cos($long2) + sin($long1) * sin($long2)) + sin($lat1) * sin($lat2);
  return acos($cosangle) * $radius;
}