public static function DmsConverter::dmsToDecimal in Geofield 8
Transforms a DMS point to a decimal one.
Parameters
\Drupal\geofield\DmsPoint $point: The DMS Point to transform.
Return value
array The equivalent Decimal Point array.
Overrides DmsConverterInterface::dmsToDecimal
2 calls to DmsConverter::dmsToDecimal()
- DmsConverterTest::testConverter in tests/
src/ Unit/ DmsConverterTest.php - @covers ::dmsToDecimal @covers ::decimalToDms
- GeofieldDmsWidget::massageFormValues in src/
Plugin/ Field/ FieldWidget/ GeofieldDmsWidget.php - Massages the form values into the format expected for field values.
File
- src/
DmsConverter.php, line 13
Class
- DmsConverter
- Helper class to convert point object from one format to the other.
Namespace
Drupal\geofieldCode
public static function dmsToDecimal(DmsPoint $point) {
$lon_data = $point
->getLon();
$lat_data = $point
->getLat();
$lon = round($lon_data['degrees'] + $lon_data['minutes'] / 60 + $lon_data['seconds'] / 3600, 10);
$lat = round($lat_data['degrees'] + $lat_data['minutes'] / 60 + $lat_data['seconds'] / 3600, 10);
$lon = $lon_data['orientation'] == 'W' ? -1 * $lon : $lon;
$lat = $lat_data['orientation'] == 'S' ? -1 * $lat : $lat;
return [
$lon,
$lat,
];
}