I have started region monitoring by calling startMonitoringForRegion
.But I found that didStartMonitoringForRegion
is getting called two times also didEnterRegion
is getting called twice. But I'm calling startMonitoringForRegion
only once. My code
- (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]);
}
Try debugging. If you don't have the time to figure it out, simply ignore the 2nd didEnterRegion
. ie If didEnterRegion
called two times consecutively for same region simply ignore 2nd one.