You are here

function geofield_latlon_DECtoDMS in Geofield 7

Same name and namespace in other branches
  1. 7.2 geofield.module \geofield_latlon_DECtoDMS()

Decimal Degrees to Decimal-Degrees-Seconds

Converts decimal longitude / latitude to DMS ( Degrees / minutes / seconds )

1 call to geofield_latlon_DECtoDMS()
geofield_field_formatter_view in ./geofield.formatters.inc
Implements hook_field_formatter_view().

File

./geofield.module, line 367

Code

function geofield_latlon_DECtoDMS($dec, $axis) {
  if ($axis == 'lat') {
    if ($dec < 0) {
      $direction = 'S';
    }
    else {
      $direction = 'N';
    }
  }
  if ($axis == 'lon') {
    if ($dec < 0) {
      $direction = 'W';
    }
    else {
      $direction = 'E';
    }
  }
  $vars = explode(".", $dec);
  $deg = abs($vars[0]);
  if (isset($vars[1])) {
    $tempma = "0." . $vars[1];
  }
  else {
    $tempma = "0";
  }
  $tempma = $tempma * 3600;
  $min = floor($tempma / 60);
  $sec = $tempma - $min * 60;
  return $deg . "&deg; " . $min . "' " . round($sec, 3) . "\" " . $direction;
}