目前,我正在学习使用 Google Maps API。据我了解,API 需要十进制度 (DD) 的纬度和经度。
在我的数据库中,数据存储为 DMS。
示例,110° 29' 01.1"
我想问问你们有没有DMS 到PHP 中的DD。并且,转换器必须像上面的示例一样接受单个字符串。
问候
最佳答案
如果这对你有用,你可以试试。
<?php
function DMStoDD($deg,$min,$sec)
{
// Converting DMS ( Degrees / minutes / seconds ) to decimal format
return $deg+((($min*60)+($sec))/3600);
}
function DDtoDMS($dec)
{
// Converts decimal format to DMS ( Degrees / minutes / seconds )
$vars = explode(".",$dec);
$deg = $vars[0];
$tempma = "0.".$vars[1];
$tempma = $tempma * 3600;
$min = floor($tempma / 60);
$sec = $tempma - ($min*60);
return array("deg"=>$deg,"min"=>$min,"sec"=>$sec);
}
?>
关于php - 在 PHP 中将度、分、秒 (DMS) 转换为十进制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22316348/