本文介绍了转换度,分,秒(DMS)在PHP十进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在学习使用谷歌地图API。从我读的API需要十进制度(DD)的经度和纬度。

Currently, I'm learning to use Google Maps API. From what I read, the API require the latitude and longitude in Decimal Degree (DD).

在我的数据库,该数据被存储为DMS。

In my database, the data is stored as DMS.

例,110°29'01.1

Example, 110° 29' 01.1"

我会问,如果你们有什么DMS在PHP到DD。而且,转换器必须从像上面的例子一个字符串接受。

I would to ask if you guys have any DMS to DD in php. And, the converter must accept from a single string like the example above.

问候

推荐答案

解决了。

 <?php

 function DMStoDD($input)
{
    $deg = " " ;
    $min = " " ;
    $sec = " " ;  
    $inputM = " " ;        


    print "<br> Input is ".$input." <br>";

    for ($i=0; $i < strlen($input); $i++) 
    {                     
        $tempD = $input[$i];
         //print "<br> TempD [$i] is : $tempD"; 

        if ($tempD == iconv("UTF-8", "ISO-8859-1//TRANSLIT", '°') ) 
        { 
            $newI = $i + 1 ;
            //print "<br> newI is : $newI"; 
            $inputM =  substr($input, $newI, -1) ;
            break; 
        }//close if degree

        $deg .= $tempD ;                    
    }//close for degree

     //print "InputM is ".$inputM." <br>";

    for ($j=0; $j < strlen($inputM); $j++) 
    { 
        $tempM = $inputM[$j];
         //print "<br> TempM [$j] is : $tempM"; 

        if ($tempM == "'")  
         {                     
            $newI = $j + 1 ;
             //print "<br> newI is : $newI"; 
            $sec =  substr($inputM, $newI, -1) ;
            break; 
         }//close if minute
         $min .= $tempM ;                    
    }//close for min

        $result =  $deg+( (( $min*60)+($sec) ) /3600 );


        print "<br> Degree is ". $deg*1 ;
        print "<br> Minutes is ". $min ;
        print "<br> Seconds is ". $sec ;
        print "<br> Result is ". $result ;


return $deg + ($min / 60) + ($sec / 3600);

   }
?>

这篇关于转换度,分,秒(DMS)在PHP十进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 13:10