You are here

function geocoder_latlon_dms_to_dec in Geocoder 7

Plugin callback.

1 call to geocoder_latlon_dms_to_dec()
geocoder_latlon in plugins/geocoder_handler/latlon.inc
Process Markup.

File

plugins/geocoder_handler/latlon.inc, line 41

Code

function geocoder_latlon_dms_to_dec($dms) {
  if (is_numeric($dms)) {

    // It's already decimal degrees, just return it.
    return $dms;
  }

  // If it contains both an H and M, then it's an angular hours.
  if (stripos($dms, 'H') !== FALSE && stripos($dms, 'M') !== FALSE) {
    $dms = strtr($dms, "'\"HOURSMINTECNDAhoursmintecnda", '  ');
    $dms = preg_replace('/\\s\\s+/', ' ', $dms);
    $dms = explode(' ', $dms);
    $deg = $dms[0];
    $min = $dms[1];
    $sec = $dms[2];
    $dec = floatval($deg * 15 + $min / 4 + $sec / 240);
    return $dec;
  }

  // If it contains an S or a W, then it's a negative.
  if (stripos($dms, 'S') !== FALSE || stripos($dms, 'W') !== FALSE) {
    $direction = -1;
  }
  else {
    $direction = 1;
  }

  // Strip all characters and replace them with empty space.
  $dms = strtr($dms, "�'\"NORTHSEAWnorthseaw'", ' ');
  $dms = preg_replace('/\\s\\s+/', ' ', $dms);
  $dms = explode(' ', $dms);
  $deg = $dms[0];
  $min = $dms[1];
  $sec = $dms[2];

  // Direction should be checked only for nonnegative coordinates.
  $dec = floatval($deg + ($min * 60 + $sec) / 3600);
  if ($dec > 0) {
    $dec = $direction * $dec;
  }
  return $dec;
}