function getlocations_convert_distance_to_meters in Get Locations 7
Same name and namespace in other branches
- 7.2 getlocations.module \getlocations_convert_distance_to_meters()
Parameters
$distance: A number in either kilometers, meters, miles, yards or nautical miles.
$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 number in meters after the initially passed scalar has been round()'d
6 calls to getlocations_convert_distance_to_meters()
- getlocations_fields_handler_argument_distance::query in modules/
getlocations_fields/ handlers/ getlocations_fields_handler_argument_distance.inc - Set up the query for this argument.
- getlocations_fields_handler_filter_distance::query in modules/
getlocations_fields/ handlers/ getlocations_fields_handler_filter_distance.inc - Add this filter to the query.
- getlocations_search_info_sql in modules/
getlocations_search/ getlocations_search.module - theme_getlocations_leaflet_map in modules/
getlocations_leaflet/ getlocations_leaflet.module - Function
- theme_getlocations_mapquest_map in modules/
getlocations_mapquest/ getlocations_mapquest.module - Function
File
- ./
getlocations.module, line 6314 - getlocations.module @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL
Code
function getlocations_convert_distance_to_meters($distance, $distance_unit = 'km') {
if (!is_numeric($distance) || !$distance > 0) {
return NULL;
}
$units = array(
'km' => 1000.0,
'm' => 1.0,
'mi' => 1609.344,
'yd' => 0.9144,
'nmi' => 1852.0,
);
if (!in_array($distance_unit, array_keys($units))) {
$distance_unit = 'km';
}
$conv = $units[$distance_unit];
// Convert distance to meters
$retval = round(floatval($distance) * $conv, 2);
return $retval;
}