【问题标题】:Using Core Location on my iPod touch在我的 iPod touch 上使用核心位置
【发布时间】:2014-02-16 17:19:20
【问题描述】:

我一直在尝试在我的设备上实现以下代码:-

 #import <UIKit/UIKit.h>
 #import <CoreLocation/CoreLocation.h>
 @interface Whereami1ViewController : UIViewController<CLLocationManagerDelegate>
  {
      CLLocationManager *locationManager;

      __weak IBOutlet UILabel *coordLabel;
  }
 @end

 @implementation Whereami1ViewController

 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
          // Custom initialization
             locationManager = [[CLLocationManager alloc] init];
              [locationManager setDelegate:self];

             [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
             locationManager.distanceFilter= 5.00;//5 meters

             [locationManager startUpdatingLocation];


         }
         return self;
       }

       -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray  *)locations{//location manager sends this message to self
          NSLog(@"%@",NSStringFromSelector(_cmd));
           NSLog(@"new location–– %@",[locations lastObject]);
           NSLog(@"latitude= %f, longitude= %f",[[locations lastObject] coordinate].latitude, [[locations lastObject] coordinate].longitude);
          CGSize coordData= {[[locations lastObject] coordinate].latitude, [[locations lastObject] coordinate].longitude};

          coordLabel.text= NSStringFromCGSize(coordData);//setting the label's text

       }
       -(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
           NSLog(@"%@",NSStringFromSelector(_cmd));
           NSLog(@"location not found: %@", error);
       }
       @end

在代码中,我将距离过滤器设置为 5 米。这意味着在设备移动 5 米后,它应该将标签的文本更新到新坐标(latitude, longitude)。但这在现实中并没有发生。我的意思是

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray  *)locations

should get called only when the device has moved more than 5 meters.实际上,设备卡在初始数据上(视图中标签没有更新)..

我做错了什么..这不是正确的方法吗??

【问题讨论】:

  • 是否调用了委托方法?

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


【解决方案1】:

iPod touch 使用 WiFi 网络进行定位服务。所以 5 米移动可能无法获得好位置或更新?!它的行为与同样使用 GPS 信号进行定位的 iPhone 或 iPda 完全不同。

【讨论】:

  • 所以你的意思是我需要让这个通过蜂窝 ip 运行?但是正常的 Wifi 网络不应该足够吗.. 我的意思是设备最终会与数据服务器通信,该服务器反过来会推送相关的位置数据..说到良好的位置,我确实将准确度属性设置为最佳.. 那怎么样代码虽然??它不应该解决预期的挑战吗?..
  • 基于 wifi 的定位服务会给出一个位置,是的。但它相当粗糙,只有在您进入其他 WiFi 节点范围时才会更新。然后对该位置进行三角测量。你想要的 5m 精度只有使用 iPod 所缺乏的 GPS 芯片才能实现。
  • iPad 怎么样。我相信它带有辅助 GPS。因为 iPhone 支持 GPS + GLONASS..
  • iPad 可以用真正的 GPS 购买,是的
  • 您可以查看this list of iOS devices 了解哪些设备具有 GPS。所有 iPhone 都有 GPS(iPhone1 除外),所有 iPad(仅 WiFi 的 iPad 除外)都有 GPS,没有 iPod Touch 有 GPS。如果没有 GPS,您只能获得 300-1000m 的精度,它需要 GPS 达到 100m 以下的精度,并且需要非常好的 GPS/Glonass 信号才能获得 5m 的精度。
猜你喜欢
  • 1970-01-01
  • 2011-11-12
  • 2011-07-13
  • 1970-01-01
  • 2011-04-01
  • 1970-01-01
  • 2010-11-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多