php - 如何将这些坐标转换为谷歌地图可读坐标?

标签 php google-maps coordinate-systems

我需要按以下形式转换坐标:

N42-53.9° 
W072-16.2°

变成类似下面的东西:

-90.7311
0.346944

一个 php 函数将不胜感激 - 或者只是一个公式也足够好。

最佳答案

我找到了一个 online JS calculator和一个 PHP solution :

<?php
function DMStoDEC($deg,$min,$sec)
{
// Converts DMS ( Degrees / minutes / seconds ) 
// to decimal format longitude / latitude

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

function DECtoDMS($dec)
{
// Converts decimal longitude / latitude to DMS
// ( Degrees / minutes / seconds ) 

// This is the piece of code which may appear to 
// be inefficient, but to avoid issues with floating
// point math we extract the integer part and the float
// part by using a string function.

    $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 - 如何将这些坐标转换为谷歌地图可读坐标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1560165/

相关文章:

android - 如何将 Google Maps API key 注入(inject) Android 应用程序?

javascript - 使用 Google Maps API 将邮政编码转换为纬度/经度坐标?

ios - 在 iOS 坐标系中,给定的位置是以像素为单位还是以其他特定单位为单位?

java - 在 Android 中使用 Hashmap 存储伪无限游戏世界时内存不足

opencv - 计算两个坐标系中给定点之间的变换

php - Doctrine 自动递增起始值 @ORM\GeneratedValue

php - 如何构建自定义 PHP Mysql 或 PDO 函数

php - 如何使用复选框删除多个条目? (PHP)

javascript - 在 html 中使用 &lt;style&gt; 和 &lt;script&gt; ……真的有那么糟糕吗?

jquery - 使用 jquery 按文本选择选项