ios - 如何在Swift 3.0中使用coreLocation框架创建20多个地理围栏

标签 ios swift3 mkmapview cllocationmanager geofencing

我目前正在使用GeoFencing,我能够借助Apple提供的CoreLocation框架创建GeoFence。但是当应用启动时,我无法创建20个以上的围栏。这是我的代码

提前致谢

 func createGeofence() {

     if CLLocationManager.isMonitoringAvailable(for: CLCircularRegion.self) {



         // region data
         let title = "Verity's"
         let coordinate = CLLocationCoordinate2DMake(17.4220382049842 , 78.3794177044913)
         let regionRadius = 150.0


         // setup region

         let region = CLCircularRegion(center:CLLocationCoordinate2D(latitude: coordinate.latitude, longitude: coordinate.longitude), radius: regionRadius, identifier: title)

         //Added monitoring
         locationManager.startMonitoring(for: region)  
     }

     else {
     }

func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion) {

       self.enterRegion = region
}


func locationManager(_ manager: CLLocationManager, didExitRegionregion: CLRegion) {

}

最佳答案

var locationManager = CLLocationManager()

@IBAction func didTapOnSaveGeoFences(_ sender: AnyObject) {
    let region = self.region(withGeotification: CLLocationCoordinate2D(latitude: (myLocation?.latitude)!, longitude: (myLocation?.longitide)!), radius: CLLocationDistance(myLocation!.distance),identifier: "\(myLocation?.locationID)", entry: true)
    locationManager.startMonitoring(for: region)
}

func region(withGeotification coordinate: CLLocationCoordinate2D, radius: CLLocationDistance, identifier: String, entry: Bool) -> CLCircularRegion {
    // 1
    let region = CLCircularRegion(center: coordinate, radius: radius, identifier: identifier)
    // 2
    region.notifyOnEntry = entry
    region.notifyOnExit = entry
    return region
}

有关更多详细信息:https://www.raywenderlich.com/136165/core-location-geofencing-tutorial

关于ios - 如何在Swift 3.0中使用coreLocation框架创建20多个地理围栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41972255/

相关文章:

ios - 如何更改 xcode 中的 .mobileprovision

objective-c - MKMapView 设置区域 : crashes at edge of world

iphone - 使 MKMapView 透明但保持覆盖层不透明

ios - Xcode:在 Instruments 中未发现僵尸

ios - 审核前更新 App Store 提交

ios - 将android代码移植到 objective-c

swift - 如何在场景中生成物体?

ios - UITableViewCell 最小化和最大化动画

swift - swift3 (xcode) 中的旋转和约束

iOS:如何获取两个坐标之间的路线路径