我想使用監控區域來跟蹤用戶是否曾訪問過地標。 外景經理是在視圖控制器初始化在視圖控制器的viewDidLoad中一個mapkitiphone CLLocationmanager區域監控回調未觸發
沿:
if (self.locationManager == nil)
{
// NSLog(@"creating location manager");
self.locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
locationManager.distanceFilter = kCLDistanceFilterNone;
}
NSSet* set=[locationManager monitoredRegions];
if ([CLLocationManager regionMonitoringAvailable] && [CLLocationManager regionMonitoringEnabled]) {
NSLog(@"region monitoring okay");
NSLog(@"monitored regions: %@",set);
}
我得到的NSLogs「區域監控好」正確和所有地區。
加入地區都像這樣
double metres=20.0;
CLLocationDistance dist=metres;
CLLocationAccuracy acc=1.0;
CLRegion *reg=[[CLRegion alloc] initCircularRegionWithCenter:coordinate radius:dist identifier:landmarkObj.landmarkName];
[locationManager startMonitoringForRegion:reg desiredAccuracy:acc];
完成,但回調都不會觸發
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Entered"
message:region.identifier
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
[alert show];
}
- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Exited"
message:region.identifier
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
[alert show];
}
- (void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region
{
NSLog(@"started monitring for region: %@",region);
}
- (void) locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error
{
NSLog(@"%@",error);
}
然而更新的位置,工作正常。
[locationManager startUpdatingLocation];
觸發回調didUpdateToLocation預期
更新:使用didUpdatToLocation監視的區域來代替。 仍然有興趣知道爲什麼這不起作用,但看起來很少有成功的區域監測
您是否找出瞭解決此問題的解決方案?我遇到了同樣的問題,並且StartStonMonitoringForRegion沒有啓動。 – Das 2012-08-06 03:15:58
事實證明,區域監控並不能提供我需要的精度。我最終爲每個didUpdateToLocation回調進行手動檢查。這對我來說是可行的,因爲我只跟蹤10個區域 – tzl 2012-08-24 06:47:40