public static function GeolocationCore::sexagesimalToDecimal in Geolocation Field 8
Transform sexagesimal notation to float.
Sexagesimal means a string like - X° Y' Z"
Parameters
string $sexagesimal: String in DMS notation.
Return value
float|false The regular float notation or FALSE if not sexagesimal.
1 call to GeolocationCore::sexagesimalToDecimal()
- GeolocationLatlngWidget::massageFormValues in src/
Plugin/ Field/ FieldWidget/ GeolocationLatlngWidget.php - Massages the form values into the format expected for field values.
File
- src/
GeolocationCore.php, line 347
Class
- GeolocationCore
- Class GeolocationCore.
Namespace
Drupal\geolocationCode
public static function sexagesimalToDecimal($sexagesimal = '') {
$pattern = "/(?<degree>-?\\d{1,3})°[ ]?((?<minutes>\\d{1,2})')?[ ]?((?<seconds>(\\d{1,2}|\\d{1,2}\\.\\d+))\")?/";
preg_match($pattern, $sexagesimal, $gps_matches);
if (!empty($gps_matches)) {
$value = $gps_matches['degree'];
if (!empty($gps_matches['minutes'])) {
$value += $gps_matches['minutes'] / 60;
}
if (!empty($gps_matches['seconds'])) {
$value += $gps_matches['seconds'] / 3600;
}
}
else {
return FALSE;
}
return $value;
}