【发布时间】:2020-01-14 11:26:29
【问题描述】:
我正在尝试为纬度/经度坐标创建一个转换器实用程序。
请看这段代码sn-p:
...
//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
正确吗? 这些字符串可以在需要纬度和经度作为参数的地方使用吗? 这是标准形式,还是需要其他小数?
【问题讨论】:
-
原始类型
double具有更高的精度,因此您应该使用double,尤其是当数学与3D 凹陷地球上的平面有关时。
标签: java android decimal latitude-longitude approximation