繁体   English   中英

如何在IOS中为CLLocationManager设置Radius

[英]How to set Radius for CLLocationManager in IOS

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

首先,您需要使用以下方法创建区域:

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    {


}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM