Rails Geokit converting GPS coordinate to Google lat long
I've got a GPS location from my Tom Tom device
S 33 22' 7.08",E 19 55' 27.44"
I need to convert that to google Lat Long. Does anyone know of an effective gem to 开发者_如何转开发to do this or code snippet capable of doing the covertion
I don't know Ruby on Rails, but I have a PHP version for converting DMS (Degrees/Minutes/Seconds) to Decimal lat/lng. Perhaps you can convert it to RoR version. Note, the code does not check (strip) for a ' or "" after the minutes and seconds. You may need to add this for your syntax.
// Converts DMS ( Degrees / minutes / seconds )
// to decimal format longitude / latitude
function GPS_DEC($coord)
{
$n = explode( " ", trim( $coord ) );
if ( count( $n ) == 1 )
return $coord;
$deg = $n[ 0 ];
$min = $sec = 0;
if ( !is_numeric( $n[ 1 ] ) )
$dir = $n[ 1 ];
else
{
$min = $n[ 1 ];
if ( !is_numeric( $n[ 2 ] ) )
$dir = $n[ 2 ];
else
{
$sec = $n[ 2 ];
$dir = $n[ 3 ];
}
}
$dec = $deg+((($min*60)+($sec))/3600);
if ( $dir == 'S' || $dir == 'W' )
$dec = -$dec;
return $dec;
}
Andrew from the Team at OpenGeoCode.Org
精彩评论