public function IpGeoLocAPI::distance in IP Geolocation Views & Maps 8
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.
string $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
- src/
Services/ IpGeoLocAPI.php, line 700
Class
- IpGeoLocAPI
- Class IpGeoAPI to interact with other modules.
Namespace
Drupal\ip_geoloc\ServicesCode
public function distance(array $location, $ref_location = 'current visitor') {
if (!is_array($ref_location)) {
$ref_location = $this
->getVisitorLocation();
}
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 '?';
}