我正在创建一个应用程序,告诉用户他们是否接近目的地。 我正在计算当前位置和目的地之间的距离。 我在 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];
}
}
];
}
我这里有什么做错了吗?
didUpdateLocations
。我不确定你是否可以依赖 GPS 如此精确地知道何时你在目标物体10米范围内。用户是否在寻找一些如此微小的东西,以至于当他们距离10米时看不到它们存在? - Craig