Tôi đang cố gắng sử dụng các vùng theo dõi để theo dõi xem người dùng đã truy cập các mốc chưa. người quản lý vị trí được khởi tạo trong một viewController cùng với một mapkitiphone CLLocationmanager Khu vực giám sát callbacks không được kích hoạt
trong viewDidLoad của bộ điều khiển xem:
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);
}
tôi nhận được NSLogs "khu vực giám sát okay" và tất cả các vùng một cách chính xác.
thêm trong những khu vực được thực hiện như vậy
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];
nhưng callbacks đều không được kích hoạt
- (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);
}
cập nhật vị trí tuy nhiên, hoạt động tốt.
[locationManager startUpdatingLocation];
kích hoạt didUpdateToLocation callback như mong đợi
Cập nhật: sử dụng didUpdatToLocation để giám sát đối với các vùng để thay thế. vẫn muốn biết lý do tại sao điều này sẽ không hoạt động, có vẻ như ít người đã thành công với việc theo dõi vùng
Bạn có tìm ra giải pháp cho vấn đề này không? Tôi gặp vấn đề tương tự và didStartMonitoringForRegion không kích hoạt. – Das
nó chỉ ra rằng theo dõi khu vực chỉ không cho tôi độ chính xác tôi cần. Tôi đã kết thúc thực hiện kiểm tra thủ công cho mọi cuộc gọi lại doUpdateToLocation. Điều này là khả thi đối với tôi vì tôi đã theo dõi chỉ 10 vùng – tzl