4

我已经通过调用开始了区域监控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]);
}
4

2 回答 2

2

尝试调试。如果您没有时间弄清楚,只需忽略 2nd didEnterRegion。即,如果didEnterRegion为同一区域连续调用两次,则只需忽略第二次。

于 2013-03-08T07:50:17.770 回答
0
[locMgr startMonitoringForRegion:myRegiondesiredAccuracy
        :kCLLocationAccuracyBest]; 

在这个方法之后为什么你不停止更新方法尝试调用停止更新方法。我认为这会对你有所帮助。

[locationManager stopUpdatingLocation];
于 2013-03-07T07:35:46.320 回答