1
我有要求,當用戶從點跨越半徑時,必須向用戶顯示警報視圖。 如何設置半徑。?如何爲IOS中的CLLocationManager設置半徑
我有要求,當用戶從點跨越半徑時,必須向用戶顯示警報視圖。 如何設置半徑。?如何爲IOS中的CLLocationManager設置半徑
首先,您需要使用創建區域:
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];
然後,當他們由以下代表進入或退出,您可以跟蹤用戶方法:
- (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 {
}