gpt4 book ai didi

java - 转换后的纬度/经度值中的小数位数(使用 Location.convert 方法)

转载 作者:行者123 更新时间:2023-12-01 18:51:25 25 4
gpt4 key购买 nike

我正在尝试创建一个纬度/经度坐标转换器实用程序。

请看一下这段代码:

    ...
//at this point the location variable has valid location information

String latDegrees = Location.convert(location.getLatitude(), Location.FORMAT_DEGREES);
String longDegrees = Location.convert(location.getLongitude(), Location.FORMAT_DEGREES);

String latMinutes = Location.convert(location.getLatitude(), Location.FORMAT_MINUTES);
String longMinutes = Location.convert(location.getLongitude(), Location.FORMAT_MINUTES);

String latSeconds = Location.convert(location.getLatitude(), Location.FORMAT_SECONDS);
String longSeconds = Location.convert(location.getLongitude(), Location.FORMAT_SECONDS);


Log.d("results ","lat "+location.getLatitude());
Log.d("results ","long "+location.getLongitude());
Log.d("results ","lat degrees "+latDegrees);
Log.d("results ","long degrees "+longDegrees);
Log.d("results ","lat min "+latMinutes);
Log.d("results ","long min "+longMinutes);
Log.d("results ","lat sec "+latSeconds);
Log.d("results ","long sec "+longSeconds);
...

我得到了这种字符串

results: lat aa.4919783
results: long bb.3432917
results: lat degrees aa.49198
results: long degrees bb.34329
results: lat min aa:29.5187
results: long min bb:20.5975
results: lat sec aa:29:31.12188
results: long sec bb:20:35.85012

(我用字母隐藏了前两位数字)

如您所见,

-原始值有7位小数

-度数为 5

-分钟有 4

-秒有5

正确吗?这些字符串可以用在需要纬度和经度作为参数的地方吗?这是标准形式,还是可能需要其他小数?

最佳答案

根据documentation ,所有转换结果最多有 5 位小数。如果小数点末尾有一位或几位 0,它们将被忽略,因此转换后的结果可以少于 5 位小数。

原始值是Double,因此没有固定的小数位

关于java - 转换后的纬度/经度值中的小数位数(使用 Location.convert 方法),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59732859/

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