iphone - 如何在IOS中为CLLocationManager设置Radius

标签 iphone ios

我有要求,当用户从点穿过半径时,我必须向用户显示警报 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/

相关文章:

ios - 在场景 View 中显示 3D map 图像

javascript - 添加到 iOS 主屏幕后,如何在 PWA 上下载动态生成的 PDF 文件?

iphone - 如何在 iPhone 中保存带有标签的图像?

ios - 谷歌登录成功后不调用委托(delegate)方法

ios - 运行循环以将颜色设置为按钮 ios?

ios - 调用自定义函数的额外参数?

iphone - 如何检索 iPhone 的区域设置

iphone - 困惑的方法 - if/then 结构和字符串操作问题

ios - Autorotation 仅适用于模拟器而不适用于设备(​​IOS 7.1)

iphone - 蓝牙连接到其他没有附件的外部 USB 蓝牙设备?