startMonitoringForRegion实际上是否工作?

我一直在尝试使用startMonitoringForRegion,但遇到问题以捕获进入/退出事件。 当我在模拟器上启动应用程序并移动到我指定的位置时,我得到1个input事件,但input从未再次触发的事件。 有人可以让我知道,如果我做得对吗?

test.h

#import <UIKit/UIKit.h> #import <CoreLocation/CoreLocation.h> @interface EWViewController : UIViewController<CLLocationManagerDelegate> { CLLocationManager *locman; } @end 

test.m

 - (void)viewDidLoad { if(locman == nil) locman = [[CLLocationManager alloc]init]; locman.delegate = self; CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(37.787359, -122.408227); CLRegion *region = [[CLRegion alloc]initCircularRegionWithCenter:coord radius:1000.0 identifier:@"SF"]; [locman startMonitoringForRegion:region desiredAccuracy:kCLLocationAccuracyKilometer]; [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void) locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region { NSLog(@"ENTER"); } - (void) locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region { NSLog(@"EXIT"); } 

是的,它的工作,但目前是非常非常前卫。 (我在俄罗斯testing过)

我build议你使用这个:

 - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation; 

我一直在我的应用程序中使用区域监视function,大约6个月,我发现它非常精确。 一旦你把所有的东西连接正确,它就可以用来很好地跟踪进入和退出事件。

虽然你可以从-didUpdateToLocation得到更好,更精确的读数,但你必须权衡电池寿命才能得到它。 如果你只需要偶尔的位置更新,那应该没问题。 如果你需要对特定地点进行持续的监测,那么地区监测就是要走的路。

我发现-startMonitoringForSignificantLocation并不准确,不太实用。 它完全依靠单元塔转换和三angular测量。 由于这个原因,它也不能用于模拟器的testing。 希望这些信息可以帮助你。