gpt4 book ai didi

ios - 从多个 CloudKit 记录创建 MapKit Circle 覆盖

转载 作者:行者123 更新时间:2023-11-30 13:21:05 25 4
gpt4 key购买 nike

我一直在尝试向我的应用程序添加一个新的 map View ,该 View 显示我的 CloudKit 数据库中所有地理围栏区域的叠加层。

目前,我可以使用以下代码从每个位置创建引脚。

func fetchData() {

let predicate = NSPredicate(format: "TRUEPREDICATE", argumentArray: nil)

let query = CKQuery(recordType: "Collection", predicate: predicate)

let operation = CKQueryOperation(query: query)
operation.desiredKeys = ["Location"]

operation.recordFetchedBlock = { (record : CKRecord) in

self.collectionLocation = record.objectForKey("Location") as? CLLocation

print(self.collectionLocation?.coordinate.latitude)

self.buildBubbles()

}

publicDB!.addOperation(operation)

operation.queryCompletionBlock = {(cursor, error) in

dispatch_async(dispatch_get_main_queue()) {

if error == nil {

} else {

print("error description = \(error?.description)")
}
}

}

}

func buildBubbles() {

if CLLocationManager.isMonitoringAvailableForClass(CLCircularRegion.self) {

let intrepidLat: CLLocationDegrees = (self.collectionLocation?.coordinate.latitude)!

let intrepidLong: CLLocationDegrees = (self.collectionLocation?.coordinate.longitude)!

let title = "Item"

let coordinate = CLLocationCoordinate2DMake(intrepidLat, intrepidLong)

let regionRadius = 300.0

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

self.locationManager.startMonitoringForRegion(region)

let restaurantAnnotation = MKPointAnnotation()

restaurantAnnotation.coordinate = coordinate;

restaurantAnnotation.title = "\(title)"

self.mapView.addAnnotation(restaurantAnnotation)

// Overlay code goes here

}

else {

print("System can't track regions")

}

}

但是当我去添加叠加层时:

let circle = MKCircle(centerCoordinate: coordinate, radius: regionRadius)

self.mapView.addOverlay(circle)

应用程序失败并出现错误:

"This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes. This will cause an exception in a future release."

我的猜测是,我在后台线程中做了太多事情,但是当我将“buildBubbles”函数移动到主队列中时,它会添加圆圈叠加层,但只将其中一个位置添加到 map 中。

感谢您花时间查看,我非常感谢任何帮助。

最佳答案

您的气泡功能界面仅提供固定一个位置的功能。尝试更改接口(interface),例如更改为数组,然后看看会得到什么。您还需要担心如何实际同步其中一个与另一个

关于ios - 从多个 CloudKit 记录创建 MapKit Circle 覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37764370/

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