ios - 在我的 iPod touch 上使用 Core Location

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

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

 #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

应该只在设备移动超过 5 米时调用。实际上,设备卡在初始数据上(标签不会在 View 中更新)。

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

最佳答案

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

关于ios - 在我的 iPod touch 上使用 Core Location,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21814645/

相关文章:

cocoa-touch - 播放时如何处理ipod库音频文件原始数据

ios - 无法使用带 Cardboard SDK 的 Kudan AR Unity 插件在 iOS 应用程序上渲染视频纹理

objective-c - 发布前xcode自动登录中的Facebook SDK Singleton?

iphone - 无法更新 uitableview 行

ios - localized.strings 文件中的超链接 - objective-c

ios - 在钥匙串(keychain)服务中使用 SecItemUpdate

ios - iphone 应用程序终止时删除文档文件夹中的文件

iphone - 如何预览UIWebview打印?

objective-c - 如何检测在 View 上添加了 UIGesture。( objective-c )

ios - 登录后主屏幕中的导航栏未出现