You are here

function _location_convert_distance_to_meters in Location 5

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

Parameters

$distance: A number in either miles or km.

$distance_unit : Either 'km' or 'mile'

Return value

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_nearby_postalcodes_bylatlon in ./location.inc
Takes a latitude, longitude, and a distance, and returns all postal_codes within
location_nearby_postalcodes_bylocation in ./location.inc
Takes an location and a distance and returns an array of all postal-codes (from all countries that are supported) within the specified distance of the specified location.
location_search_results in ./location.module

File

./location.inc, line 725

Code

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

  // Force an integer version of distance, just in case anyone wants to add a caching mechanism
  // for postal code proximity searches.
  if (is_float($distance)) {
    $distance = intval(ceil($distance));
  }
  if ($distance < 1) {
    return NULL;
  }
  if ($distance_unit != 'km' && $distance_unit != 'mile') {
    $distance_unit = 'km';
  }

  // Convert distance to meters

  //$distance_float = floatval($distance) * (($distance_unit == 'km') ? 1000.0 : 1609.347);

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