1

我有要求,当用户从该点穿过半径时,我必须向用户显示警报视图。如何设置半径。?

4

1 回答 1

2

首先,您需要使用以下命令创建区域:

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    {


}
于 2013-05-15T05:34:13.460 回答