【问题标题】:What is the best and most precise data type for storing latitude longitude in iphone xcode?在 iphone xcode 中存储纬度经度的最佳和最精确的数据类型是什么?
【发布时间】:2011-11-08 08:38:50
【问题描述】:

我正在构建一个基于地理定位的应用程序,我想知道哪种数据类型最适合存储纬度/经度我正在使用 doubleValue,但我认为我们可以更精确,例如小数点后 10 位。

【问题讨论】:

    标签: ios objective-c cocoa-touch core-location


    【解决方案1】:

    不会,因为iOS 使用的纬度/经度也是双精度值。

    /*
     *  CLLocationDegrees
     *  
     *  Discussion:
     *    Type used to represent a latitude or longitude coordinate in degrees under the WGS 84 reference
     *    frame. The degree can be positive (North and East) or negative (South and West).  
     */
    typedef double CLLocationDegrees;
    

    【讨论】:

      【解决方案2】:

      double 是 iOS 本身使用的值。 iOS 使用CLLocationDegrees 表示纬度/经度值,它是 doubletypedef

      IMO,使用double/CLLocationDegrees 将是最佳选择。

      【讨论】:

      • 为什么不使用CLLocationDegrees
      • CLLocationDegrees 只是 double 的 typedef。但是看到Dean 的最新评论最好使用 CLLocationDegrees
      • @deanWombourne, ;-) 当然。我已经提到 CLLocationDegrees 是 double 的 typedef。
      • 我的意思是你不应该关心它是什么 - 它可能会在 SDK 的更高版本中发生变化(好吧,在这种情况下不太可能,但你明白我的意思!)。
      • 好的。无论如何,我认为 Apple 没有必要将 CLLocationDegressdouble 更改为其他类型,因为 double 足以容纳经度/纬度。
      【解决方案3】:

      iOS SDK 中已经有答案了 :)

      获取look at CLLocationCoordinate2D - CoreLocation 使用它使用 CLLocationDegrees 类型存储它的纬度/经度。如果这是 CoreLocation 为您提供的准确度,那么这就是它将会得到的准确度!

      【讨论】:

        【解决方案4】:

        看CLLocationCoordinate2D的定义:

        typedef struct {
            CLLocationDegrees latitude;
            CLLocationDegrees longitude;
        } 
        CLLocationCoordinate2D;
        

        然后是CLLocationDegrees的位置;

        typedef double CLLocationDegrees;
        

        我们可以看到精度是双倍的。因此,你不能做得比这更好。

        【讨论】:

          猜你喜欢
          • 2018-01-27
          • 2010-09-27
          • 1970-01-01
          • 2011-08-01
          • 2011-12-30
          • 2012-03-22
          • 2017-03-22
          • 2011-09-15
          • 2012-12-01
          相关资源
          最近更新 更多