Rails Geokit将GPS坐标转换为Google lat long

时间:2011-03-10 08:33:48

标签: ruby-on-rails-3 geolocation

我的Tom Tom设备上有GPS位置

S 33 22' 7.08",E 19 55' 27.44" 

我需要将其转换为Google Lat Long。有没有人知道这样做的有效宝石或能够进行转换的代码片段

1 个答案:

答案 0 :(得分:0)

我不知道Ruby on Rails,但我有一个PHP版本,用于将DMS(度/分/秒)转换为Decimal lat / lng。也许您可以将其转换为RoR版本。注意,代码不会在分钟和秒后检查(剥离)“或”。您可能需要为语法添加此内容。

// 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;
}
来自OpenGeoCode.Org团队的安德鲁

相关问题