DidStartMonitoringForRegion receives a call twice to start startMonitoringForRegion

I started monitoring the area by calling startMonitoringForRegion . But I found that didStartMonitoringForRegion gets called twice, and didEnterRegion called twice. But I call 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]); } 
+4
source share
2 answers

Try debugging. If you don't have time to figure this out, just ignore the second didEnterRegion . those. If didEnterRegion , called twice in a row for the same area, just ignores the second.

+2
source
 [locMgr startMonitoringForRegion:myRegiondesiredAccuracy :kCLLocationAccuracyBest]; 

After this method, why don't you stop the update method, try calling the update stop method. I think this will help you.

 [locationManager stopUpdatingLocation]; 
0
source

All Articles