我有要求,当用户从点穿过半径时,我必须向用户显示警报 View 。 如何设置半径?
最佳答案
首先您需要使用以下方法创建区域:
CLLocationDegrees latitude = <YOUR_LATITUDE>;
CLLocationDegrees longitude = <YOUR_LONGITUDE>;
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(latitude, longitude);
CLLocationDistance radius = GEO_FENCE_RADIUS;
CLRegion *region = [[CLRegion alloc]initCircularRegionWithCenter:center radius:radius identifier:title];
接下来您必须通过以下方式监控区域:
[locationManager startMonitoringForRegion:region];
然后您可以通过以下委托(delegate)方法跟踪用户何时进入或退出:
- (void)locationManager:(CLLocationManager *)manager
didEnterRegion:(CLRegion *)region {
//Show your alert as they are entered the region
}
- (void)locationManager:(CLLocationManager *)manager
didExitRegion:(CLRegion *)region {
//Show your alert as they are exited the region
}
- (void)locationManager:(CLLocationManager *)manager
didStartMonitoringForRegion:(CLRegion *)region {
}
- (void)locationManager:(CLLocationManager *)manager
monitoringDidFailForRegion:(CLRegion *)region
withError:(NSError *)error {
}
关于iphone - 如何在IOS中为CLLocationManager设置Radius,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16557403/