You are here

function _location_convert_distance_to_meters in Location 7.3

Same name and namespace in other branches
  1. 5.3 location.inc \_location_convert_distance_to_meters()
  2. 5 location.inc \_location_convert_distance_to_meters()
  3. 6.3 location.inc \_location_convert_distance_to_meters()
  4. 7.5 location.inc \_location_convert_distance_to_meters()
  5. 7.4 location.inc \_location_convert_distance_to_meters()

Convert distances to meter.

Parameters

int $distance: A number in either miles or km.

string $distance_unit: String (optional). Either 'mile' or 'km' (default)

Return value

float A floating point number where the number in meters after the initially passed scalar has been ceil()'d This is done after the $distance_unit parmeter is forced to be 'km' or 'mile'

3 calls to _location_convert_distance_to_meters()
location_handler_argument_location_proximity::query in handlers/location_handler_argument_location_proximity.inc
Set up the query for this argument.
location_search_search_execute in contrib/location_search/location_search.module
Implements hook_search_execute().
location_views_handler_filter_proximity::query in handlers/location_views_handler_filter_proximity.inc
Add this filter to the query.

File

./location.inc, line 326
Public API for the Location module.

Code

function _location_convert_distance_to_meters($distance, $distance_unit = 'km') {
  if (!is_numeric($distance)) {
    return NULL;
  }
  if ($distance == 0) {
    return NULL;
  }
  if ($distance_unit != 'km' && $distance_unit != 'mile') {
    $distance_unit = 'km';
  }

  // Convert distance to meters.
  $retval = round(floatval($distance) * ($distance_unit == 'km' ? 1000.0 : 1609.347), 2);
  return $retval;
}