public static function DmsConverter::decimalToDms in Geofield 8
Transforms a Decimal point to a dms one.
Parameters
float $lon: The Decimal Point to transform longitude.
float $lat: The Decimal Point to transform latitude.
Return value
\Drupal\geofield\DmsPoint The equivalent DMS Point object.
Overrides DmsConverterInterface::decimalToDms
3 calls to DmsConverter::decimalToDms()
- DmsConverterTest::testConverter in tests/
src/ Unit/ DmsConverterTest.php - @covers ::dmsToDecimal @covers ::decimalToDms
- GeofieldDms::dmsProcess in src/
Element/ GeofieldDms.php - Generates the Geofield DMS form element.
- LatLonFormatter::getDmsComponents in src/
Plugin/ Field/ FieldFormatter/ LatLonFormatter.php - Generates the DMS expected components given a Point.
File
- src/
DmsConverter.php, line 28
Class
- DmsConverter
- Helper class to convert point object from one format to the other.
Namespace
Drupal\geofieldCode
public static function decimalToDms($lon, $lat) {
$lat_direction = $lat < 0 ? 'S' : 'N';
$lon_direction = $lon < 0 ? 'W' : 'E';
$lat_in_degrees = floor(abs($lat));
$lon_in_degrees = floor(abs($lon));
$la_decimal = (abs($lat) - $lat_in_degrees) * 60;
$lon_decimal = (abs($lon) - $lon_in_degrees) * 60;
$lat_minutes = floor($la_decimal);
$lon_minutes = floor($lon_decimal);
$la_decimal = ($la_decimal - $lat_minutes) * 60;
$lon_decimal = ($lon_decimal - $lon_minutes) * 60;
$lat_seconds = round($la_decimal);
$lon_seconds = round($lon_decimal);
return new DmsPoint([
'orientation' => $lon_direction,
'degrees' => $lon_in_degrees,
'minutes' => $lon_minutes,
'seconds' => $lon_seconds,
], [
'orientation' => $lat_direction,
'degrees' => $lat_in_degrees,
'minutes' => $lat_minutes,
'seconds' => $lat_seconds,
]);
}