Cam*_*mus 3 core-location cllocationmanager ios clregion region-monitoring
我正在创建一个应用程序,告诉用户他们是否在目的地附近.我正在计算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];
}
}
];
}
Run Code Online (Sandbox Code Playgroud)
我在这里做错了吗?
Bil*_*ess 10
好的,在iOS中使用区域监控功能时要记住一些事项.
你的代码看起来不错,但却缺少你的代码CLLocationManagerDelegate.没有适当的委托来处理回调,你可能只是错过了回调(-didExitRegion/-didEnterRegion).
根据我的经验,我创建了一个单例类来处理我的所有位置管理器委托方法.请务必注册以收听他们.如果你包含一些围绕这些委托电话的代码,我很乐意为你提供更多帮助.有很多教程应该记录如何正确设置它们.祝好运.
*注意:今年我在WWDC与位置工程师谈到了围绕最小区域大小和区域数量的许多未知因素.我可以确认最小区域大小为100,但不是最大区域数.到目前为止我还没有必要.
| 归档时间: |
|
| 查看次数: |
3893 次 |
| 最近记录: |