English 中文(简体)
将小数点转换为纬度和经度
原标题:Convert decimal to latitude and longitude

我有一个 GPS 设备, 将数据发送到我的服务器, 我需要转换该设备发送到纬度和经度的十进制值。 我数学不好, 所以所有尝试都失败了, 下面是图示 :

> 纬度

占有4字节,代表纬度值。

Number range is from 0 to 162000000, which represents the range form 0°to 90°. Unit: 1/500 second Conversion method:

A) 将GPS模块的纬度(度、分)数据转换成新形式,仅代表分钟值;

B 乘以3000乘以换算值,然后将结果转换为十六进制数字

例如22°32.7658},(22x60+32.7658x30000=40582974),然后转换成十六进制数 0x02 0x6B 0x3F 0x3E

经度

使用 4 字节, 表示位置数据的经度值 。 数字介于 0 到 324000000 之间, 代表 0 ° 到 180 ° 。 单位: 1/ 500 秒, 转换方法与纬度相同 。

我提出这个职能,但似乎行不通:

procedure GetDegree(const numar : DWORD; out min,sec : Extended);
var
  eu : Extended;
begin
  eu :=  numar / 30000;
  min := Trunc(eu / 60);
  sec := eu - min * 60;
end;
最佳回答

numar 在秒的 1/ 500 中指定。 因此, 下列方程式持有 :

num/500 = seconds
num/500/60 = minutes
num/500/60/60 = degrees

我会这样计算:

var
  degrees, minutes, seconds: Integer;
....
  degrees := num div (500*60*60);
  minutes := num div (500*60) - degrees*60;
  seconds := num div 500 - minutes*60 - degrees*60*60;

如果您需要计算秒的分数部分, 请像这样做 。 请注意, 这里根本不需要 < code> expended

var
  degrees, minutes: Integer;
  seconds: Double;
....
  degrees := num div (500*60*60);
  minutes := num div (500*60) - degrees*60;
  seconds := num/500 - minutes*60 - degrees*60*60;

将你40582974的值插入这些公式,结果如下:

degrees: 22
minutes: 32
seconds: 45

从评论中判断,你真正想要的是一个整数度和一个浮点的分数。你可以这样做:

var
  degrees: Integer;
  minutes: Double;
....
  degrees := num div (500*60*60);
  minutes := num/(500*60) - degrees*60;

将你40582974的值插入这些公式,结果如下:

degrees: 22
minutes: 32.7658
问题回答

暂无回答




相关问题
How to add/merge several Big O s into one

If I have an algorithm which is comprised of (let s say) three sub-algorithms, all with different O() characteristics, e.g.: algorithm A: O(n) algorithm B: O(log(n)) algorithm C: O(n log(n)) How do ...

Grokking Timsort

There s a (relatively) new sort on the block called Timsort. It s been used as Python s list.sort, and is now going to be the new Array.sort in Java 7. There s some documentation and a tiny Wikipedia ...

Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Enumerating All Minimal Directed Cycles Of A Directed Graph

I have a directed graph and my problem is to enumerate all the minimal (cycles that cannot be constructed as the union of other cycles) directed cycles of this graph. This is different from what the ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签