Tuesday, March 31, 2009

/**
* Convert Latitude Longitude Decimal To Minutes
*
* decimalToMinutes(-122.56334) returns array("deg"=>-122, "min"=>33, "sec"=>48.0234)
*
* @param int $value Value to be Converted
*/
function decimalToMinutes($value){
$pos = ($value < 0) ? -1:1;
$abs = abs(round($value, 6));
$deg = floor($abs)*$pos;
$min = floor(($abs-floor($abs))*60);
$sec = round((((($abs-floor($abs))*60)-$min)*60), 4);
return array("deg"=>$deg, "min"=>$min, "sec"=>$sec);
}
/**
* Convert Latitude Longitude Minutes To Decimal
*
* minutesToDecimal(-122 33 48.0234) returns int -122.56334
*
* @param string $value Value to be Converted
*/
function minutesToDecimal($value){
list($deg,$min,$sec) = explode(' ',$value);
$pos = ($deg < 0) ? -1:1;
$deg = abs(round($deg,6));
$min = abs(round($min,6));
$sec = abs(round($sec,6));
return round($deg+($min/60)+($sec/3600),6)*$pos;
}

No comments: