public static function GeolocationCore::decimalToSexagesimal in Geolocation Field 8
Transform decimal notation to sexagesimal.
Sexagesimal means a string like - X° Y' Z"
Parameters
float|string $decimal: Either float or float-castable location.
Return value
string|false The sexagesimal notation or FALSE on error.
3 calls to GeolocationCore::decimalToSexagesimal()
- GeolocationItemTokenTrait::geolocationItemTokens in src/
GeolocationItemTokenTrait.php - Token replacement support function, callback to token replacement function.
- GeolocationLatlngWidget::formElement in src/
Plugin/ Field/ FieldWidget/ GeolocationLatlngWidget.php - Returns the form for a single field widget.
- GeolocationSexagesimalFormatter::viewElements in src/
Plugin/ Field/ FieldFormatter/ GeolocationSexagesimalFormatter.php - Builds a renderable array for a field value.
File
- src/
GeolocationCore.php, line 378
Class
- GeolocationCore
- Class GeolocationCore.
Namespace
Drupal\geolocationCode
public static function decimalToSexagesimal($decimal = '') {
$decimal = (double) $decimal;
$degrees = floor($decimal);
$rest = $decimal - $degrees;
$minutes = floor($rest * 60);
$rest = $rest * 60 - $minutes;
$seconds = round($rest * 60, 4);
$value = $degrees . '°';
if (!empty($minutes)) {
$value .= ' ' . $minutes . '\'';
}
if (!empty($seconds)) {
$value .= ' ' . $seconds . '"';
}
return $value;
}