gpt4 book ai didi

php - 在 PHP 中将度、分、秒 (DMS) 转换为十进制

转载 作者:可可西里 更新时间:2023-11-01 13:10:14 26 4
gpt4 key购买 nike

目前,我正在学习使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com