You are here

function getlocations_distance_between in Get Locations 7.2

Same name and namespace in other branches
  1. 7 getlocations.module \getlocations_distance_between()

Given two points in lat/lon form, returns the distance between them.

Parameters

$latlon_a: An associative array where 'lon' => is a floating point of the longitude coordinate for the point given by latlonA 'lat' => is a floating point of the latitude coordinate for the point given by latlonB

$latlon_b: Another point formatted like $latlon_b

$distance_unit: A string that is one of 'km', 'm', 'mi', 'yd', 'nmi'. Defaults to 'km'

Return value

NULL if sense can't be made of the parameters. An associative array where 'scalar' => Is the distance between the two lat/lon parameter points 'distance_unit' => Is the unit of distance being represented by 'scalar'.

1 call to getlocations_distance_between()
getlocations_getinfo in ./getlocations.module

File

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

Code

function getlocations_distance_between($latlon_a = array(), $latlon_b = array(), $distance_unit = 'km') {
  if (!isset($latlon_a['lon']) || !isset($latlon_a['lat']) || !isset($latlon_b['lon']) || !isset($latlon_b['lat'])) {
    return NULL;
  }
  $meters = getlocations_earth_distance($latlon_a['lon'], $latlon_a['lat'], $latlon_b['lon'], $latlon_b['lat']);
  $distance = getlocations_convert_meters_to_distance($meters, $distance_unit);
  return array(
    'scalar' => $distance,
    'distance_unit' => $distance_unit,
  );
}