【问题标题】:Number of decimal digits in converted latitude/longitude values (with Location.convert method)转换后的纬度/经度值中的小数位数(使用 Location.convert 方法)
【发布时间】: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


【解决方案1】:

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

原来的值是Double,所以它没有固定的小数位

【讨论】:

  • 那么为什么分钟有4,也许第五位是0?
  • 这是因为这个函数是使用 DecimalFormat("###.#####") 来实现转换的(见android源码:android.googlesource.com/platform/frameworks/base/+/refs/heads/…)。是的,第五位数字是 0。
  • 这个数字是否也有可能是一个没有小数位和没有点的整数,比如20?
猜你喜欢
  • 2017-10-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-19
  • 2015-03-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多