【问题标题】:Conversion of GPS values from deg to dms formatGPS 值从 deg 到 dms 格式的转换
【发布时间】:2011-09-06 00:49:48
【问题描述】:

有谁知道如何或有 Android 功能将 GPS 值从十进制转换为 DMS(度-分-秒)格式?

【问题讨论】:

    标签: android dictionary gps


    【解决方案1】:

    看看课程android.location.Location

    静态方法convert(double, Location.FORMAT_SECONDS) 就是您要找的。​​p>

    【讨论】:

      【解决方案2】:

      您可以手动计算。

      示例代码:

      decimal = ...;  // Your given value
      
      boolean neg = decimal < 0;
      decimal = abs(decimal);
      
      deg = floor(decimal);                  // Round down
      minutes = floor((decimal * 60) % 60);  // This is an integer in the range [0, 60)
      seconds = (decimal * 3600) % 60;       // This is a decimal in the range [0, 60)
      
      if (neg) prepend minus sign;
      

      【讨论】:

      • 几乎正确。唯一的问题是,它会给你错误的答案是南半球的纬度和西半球的经度(floor (-74.0125) 是 -75,但经度是 74° 0′ 45″ W)。
      • // Your given value, assumed to be nonnegative
      • 但 GPS 坐标不能假定为非负数。
      • +1 虽然我通常会使用 neg 标志来附加 N/S/E/W
      • 我知道您可以自行进行修改。
      猜你喜欢
      • 2022-01-04
      • 1970-01-01
      • 2021-01-04
      • 2018-05-02
      • 1970-01-01
      • 2020-04-21
      • 1970-01-01
      • 1970-01-01
      • 2013-06-16
      相关资源
      最近更新 更多