目的地の近くにいるかどうかをユーザーに知らせるアプリを作成しています。と目的地の間の距離を計算してcurrentLocation
います。内で計算を行っていdidUpdateLocations
ます。それは機能していますが、数学をしなくてもそれを処理できる方法があることを私は見ました。
地域を登録していCLLocationManager
ます; ただし、メソッドdidExitRegion
とdidEnterRegion
は呼び出されていないようです。
リージョンを登録するコードの部分は次のとおりです。
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
[self.locationManager startUpdatingLocation];
[self.mySearchBar resignFirstResponder];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
self.distToRemind = 0;
[worldMap removeAnnotations:[worldMap annotations]];
NSLog(@"executou de primeira");
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:[self.mySearchBar text] completionHandler:^(NSArray *placemarks, NSError *error)
{
CLPlacemark *placemark = [placemarks lastObject];
//test
//DefaultAnnotation *annot = [[DefaultAnnotation alloc] initWithCoordinate:placemark.location.coordinate andTitle:@""];
CLRegion *newRegion = [[CLRegion alloc] initCircularRegionWithCenter:placemark.location.coordinate radius:10.0 identifier:@"RegionBoundary"];
DefaultAnnotation *regionAnnotation = [[DefaultAnnotation alloc] initWithCoordinate:newRegion.center andTitle:@""];
[self identifyPlacemark:placemark andSetAnnotation:regionAnnotation];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(regionAnnotation.coordinate, 250, 250);
[worldMap addAnnotation:regionAnnotation];
[worldMap setRegion:region animated:YES];
[self.locationManager startMonitoringForRegion:newRegion];
if (self.boolPushButtonTapped) {
[self pushButtonTapped];
}
}
];
}
私はここで何か間違ったことをしていますか?