You are here

function ip_geoloc_distance in IP Geolocation Views & Maps 7

Same name and namespace in other branches
  1. 8 ip_geoloc_api.inc \ip_geoloc_distance()

Returns the distance (in meters) between two points on the earth's surface.

The points are defined by their lat/long coordinates. If the second point is omitted, the current visitor's location is used, as taken from their session data.

Parameters

array $location: must contain 'latitude' and 'longitude' keys and values

array $ref_location: if an array, must contain 'latitude' and 'longitude' keys and values, otherwise defaults to ip_geoloc_get_visitor_location()

Return value

float distance in meters.

File

./ip_geoloc_api.inc, line 684
API functions of IP geolocation module

Code

function ip_geoloc_distance($location, $ref_location = 'current visitor') {
  if (!is_array($ref_location)) {
    $ref_location = ip_geoloc_get_visitor_location();
  }
  if (empty($ref_location)) {
    return '?';
  }
  if (is_numeric($location['longitude']) && is_numeric($location['latitude']) && is_numeric($ref_location['longitude']) && is_numeric($ref_location['latitude'])) {
    return ip_geoloc_earth_distance($location['longitude'], $location['latitude'], $ref_location['longitude'], $ref_location['latitude']);
  }
  return '?';
}