<?php
/**
* Helpers to process geo coordinates
*/
class GeoUtils {
/**
* Convert latitude into Degrees, Minutes, Seconds
* @param $i Latitude
*/
public function getDMSLatitude($i) {
$d = ($i>0) ? 'N' : 'S';
return $this->gpsconv_dec_dms($i) . ' ' . $d;
}
/**
* Convert longitude into Degrees, Minutes, Seconds
* @param $i Longitude
*/
public function getDMSLongitude($i) {
$d = ($i>0) ? 'E' : 'W';
return $this->gpsconv_dec_dms($i) . ' ' . $d;
}
/**
* Convert from decimal to Degrees, Minutes, Seconds
*/
private function gpsconv_dec_dms( $fl_deg ) {
// assume input is in the form "123.45678"
$fl_deg = abs( $fl_deg );
while ( $fl_deg > 360.0 ) {
$fl_deg -= 360.0;
}
$deg = intval( $fl_deg );
$fl_secs = 3600.0 * ( $fl_deg - floatval( $deg ) );
$min = intval( $fl_secs / 60.0 );
$fl_fract = ( $fl_secs / 60.0 ) - floatval( $min );
$sec = round( 60.0 * $fl_fract );
if ( $sec < 10 ) {
$sec = '0' . $sec;
}
return( "$deg° $min' $sec\"" );
}
}
?>