开发者

Rails Geokit converting GPS coordinate to Google lat long

开发者 https://www.devze.com 2023-02-16 10:50 出处:网络
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 o

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号