You are here

function getlocations_convert_meters_to_distance in Get Locations 7

Same name and namespace in other branches
  1. 7.2 getlocations.module \getlocations_convert_meters_to_distance()

Parameters

$meters: The distance in meters.

$distance_unit: String (optional). in either kilometers (km), meters (m), miles (mi), yards (yd) or nautical miles (nmi).

Return value

A floating point number where the converted number has been round()'d

2 calls to getlocations_convert_meters_to_distance()
getlocations_distance_between in ./getlocations.module
Given two points in lat/lon form, returns the distance between them.
getlocations_fields_handler_field_distance::render in modules/getlocations_fields/handlers/getlocations_fields_handler_field_distance.inc
Render the field.

File

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

Code

function getlocations_convert_meters_to_distance($meters, $distance_unit = 'km') {
  if (!is_numeric($meters) || !$meters > 0) {
    return NULL;
  }
  $units = array(
    'km' => 0.001,
    'm' => 1.0,
    'mi' => 0.000621371,
    'yd' => 1.093613298,
    'nmi' => 0.000539957,
  );
  if (!in_array($distance_unit, array_keys($units))) {
    $distance_unit = 'km';
  }
  $conv = $units[$distance_unit];

  // Convert meters to display units. formatting in theme_getlocations_fields_distance();
  $retval = $meters * $conv;
  return $retval;
}