如何将GPS度转换为十进制,反之亦然在jquery或JavaScript和PHP? [英] How to convert GPS degree to decimal and vice-versa in jquery or javascript and PHP?

查看:103
本文介绍了如何将GPS度转换为十进制,反之亦然在jquery或JavaScript和PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何将GPS度数转换为十进制数值,反之亦然?

我必须开发一种方式,让用户可以插入地址并获取GPS值(包括度和/或小数),但我需要知道的主要是如何转换值,导致用户也可以插入GPS值(度或小数)。因为我需要从谷歌地图得到地图这需要十进制。



我已经尝试了一些代码,但我得到大数字...像这样:

 函数ConvertDMSToDD(天,分,秒,方向){
var dd =天+分/ 60 +秒/(60 * 60);
// alert(dd);
if(direction ==S|| direction ==W){
dd =' - '+ dd;
} //不要为N或E
返回dd;

$ / code>

任何一个?

感谢您。

解决方案

首先感谢@Eugen Rieck的帮助。
这里是我的最终代码,希望它可以帮助别人:

度数到小数点



<$ p $函数getDMS2DD(日,分,秒,方向){
direction.toUpperCase();
var dd =天+分/ 60 +秒/(60 * 60);
// alert(dd);
if(direction ==S|| direction ==W){
dd = dd * -1;
} //不要为N或E
返回dd;
}

基于此 link

  function getDD2DMS(dms,type){

var sign = 1,Abs = 0;
var days,minutes,secounds,direction;

if(dms <0){sign = -1; }
Abs = Math.abs(Math.round(dms * 1000000.));
//Math.round用于消除由计算机舍入引起的小错误:
//例如, 0.2不等于0.20000000000284
//错误检查
if(type ==lat&& Abs>(90 * 1000000)){
// alert(度纬度必须在-90到90之间。);
返回false;
} else if(type ==lon&& Abs>(180 * 1000000)){
// alert(Degrees Longitude必须在-180到180的范围内。 );
返回false;
}

days = Math.floor(Abs / 1000000);
分钟= Math.floor(((Abs / 1000000) - 天)* 60); (((((Abs / 1000000) - 天)* 60) - 分钟)* 100000)* 60/100000).toFixed();
天=天*号;
if(type =='lat')direction = days <0? 'S':'N';
if(type =='lon')direction = days <0? 'W':'E';
// else return value
return(days * sign)+'º'+ minutes +'+ secounds +''+ direction;
}
alert(getDD2DMS(-8.68388888888889,'lon'));

`


does someone know how to convert GPS degree to decimal values or vice versa?

I have to develop a way where users can insert an address and get the GPS values (both degree and/or decimal), but the main thing i need to know is how to convert the values, cause users can also insert GPS values (degree or decimal). Because i need to get the map from google maps this needs decimal.

I've tryed some codes but i get big numbers...like this one:

function ConvertDMSToDD(days, minutes, seconds, direction) {
    var dd = days + minutes/60 + seconds/(60*60);
    //alert(dd);
    if (direction == "S" || direction == "W") {
        dd = '-' + dd;
    } // Don't do anything for N or E
    return dd;
}

Any one?

Thank you.

解决方案

First thank you @Eugen Rieck for your help. Here is my final code, hope it can help someone:

degree to decimal

function getDMS2DD(days, minutes, seconds, direction) {
    direction.toUpperCase();
    var dd = days + minutes/60 + seconds/(60*60);
    //alert(dd);
    if (direction == "S" || direction == "W") {
        dd = dd*-1;
    } // Don't do anything for N or E
    return dd;
}

decimal to degree based on this link

function getDD2DMS(dms, type){

    var sign = 1, Abs=0;
    var days, minutes, secounds, direction;

    if(dms < 0)  { sign = -1; }
    Abs = Math.abs( Math.round(dms * 1000000.));
    //Math.round is used to eliminate the small error caused by rounding in the computer:
    //e.g. 0.2 is not the same as 0.20000000000284
    //Error checks
    if(type == "lat" && Abs > (90 * 1000000)){
        //alert(" Degrees Latitude must be in the range of -90. to 90. ");
        return false;
    } else if(type == "lon" && Abs > (180 * 1000000)){
        //alert(" Degrees Longitude must be in the range of -180 to 180. ");
        return false;
    }

    days = Math.floor(Abs / 1000000);
    minutes = Math.floor(((Abs/1000000) - days) * 60);
    secounds = ( Math.floor((( ((Abs/1000000) - days) * 60) - minutes) * 100000) *60/100000 ).toFixed();
    days = days * sign;
    if(type == 'lat') direction = days<0 ? 'S' : 'N';
    if(type == 'lon') direction = days<0 ? 'W' : 'E';
    //else return value     
    return (days * sign) + 'º ' + minutes + "' " + secounds + "'' " + direction;
}
alert(getDD2DMS(-8.68388888888889, 'lon'));

`

这篇关于如何将GPS度转换为十进制,反之亦然在jquery或JavaScript和PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆