我已经通过调用startMonitoringForRegion
启动了区域监控。但我发现didStartMonitoringForRegion
被调用了两次didEnterRegion
被调用了两次。但我只打电话给startMonitoringForRegion
一次。我的代码
- (void) enableRegionMonitoring:(NSMutableDictionary *)locationInfoDic{
NSLog(@"started Loc Mon");
locMgr = [[CLLocationManager alloc] init];
[locMgr setDelegate:self];
NSString *locationId=[[NSString alloc]init];
double latitude=[[locationInfoDic objectForKey:@"lat"] doubleValue];
double longitude=[[locationInfoDic objectForKey:@"lon"] doubleValue];
if([locationInfoDic objectForKey:@"key"]){
locationId=[locationInfoDic objectForKey:@"key"] ;
}else{
locationId=@"NA";
}
CLLocationCoordinate2D myMonLocation = CLLocationCoordinate2DMake(latitude, longitude);
CLRegion *myRegion = [[CLRegion alloc]
initCircularRegionWithCenter:myMonLocation
radius:100
identifier:locationId];
[locMgr startMonitoringForRegion:myRegion
desiredAccuracy:kCLLocationAccuracyBest];
}
- (void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region{
NSLog(@"Region monitoring started\n%@",[region description]);
}
答案 0 :(得分:2)
尝试调试。如果您没有时间弄清楚,只需忽略第二个didEnterRegion
。即如果同一区域连续两次调用didEnterRegion
,则忽略第二个。
答案 1 :(得分:0)
[locMgr startMonitoringForRegion:myRegiondesiredAccuracy
:kCLLocationAccuracyBest];
在这个方法之后为什么你没有停止更新方法尝试调用停止更新方法。我想这会对你有帮助。
[locationManager stopUpdatingLocation];