gpt4 book ai didi

c# - 将纬度和经度转换为 double 值的最简单方法是什么

转载 作者:太空狗 更新时间:2023-10-29 17:36:33 24 4
gpt4 key购买 nike

我有一个包含纬度和经度值的 CSV 文件,例如:

"25°36'55.57""E","45°39'12.52""N"

谁有一段快速简单的 C# 代码可以将其转换为 double 值?

谢谢

最佳答案

如果您指的是 C# 代码来执行此操作:

结果 = 25 + (36/60) + (55.57/3600)

首先,您需要使用 Regex 或其他一些机制来解析表达式,并将其拆分为各个部分。然后:

String hour = "25";
String minute = "36";
String second = "55.57";
Double result = (hour) + (minute) / 60 + (second) / 3600;

当然还有根据 N/S 或 E/S 切换到翻转符号。维基百科对此有一些介绍:

For calculations, the West/East suffix is replaced by a negative sign in the western hemisphere. Confusingly, the convention of negative for East is also sometimes seen. The preferred convention -- that East be positive -- is consistent with a right-handed Cartesian coordinate system with the North Pole up. A specific longitude may then be combined with a specific latitude (usually positive in the northern hemisphere) to give a precise position on the Earth's surface. (http://en.wikipedia.org/wiki/Longitude)

关于c# - 将纬度和经度转换为 double 值的最简单方法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/103006/

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