我已經開始區域監測。但我發現,didStartMonitoringForRegion
獲取調用兩次也didEnterRegion
獲取調用兩次。但我只打一次電話startMonitoringForRegion
。我的代碼didStartMonitoringForRegion獲取調用兩次,一個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{
[email protected]"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]);
}
這個答案並不完全知道爲什麼'didEnterRegion'被調用了兩次,因此它不是一個正確的答案? – 2014-03-23 09:26:48