gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 22:26:41 25 4
gpt4 key购买 nike

我目前正在使用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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com