我正在用要显示的数千个数据改进我的MapView的性能。我已经完成了集群,并且每次用户平移地图的摄像头时都会加载一组新的数据,为了避免网络请求的垃圾邮件,我添加了一个节流阀。
不过,我的下一个想法是删除现有的注释
如果
它们在当前摄像机的外面。问题是:如果给定的坐标/注释在当前相机的外部或内部,我如何计算?
这是我的代码:
@objc func throttleDone() {
let newCoordinatesOfCamera = self.mapView.camera.centerCoordinate
let newLocationOfCamera = CLLocation(latitude: newCoordinatesOfCamera.latitude, longitude: newCoordinatesOfCamera.longitude)
// Remove current annotations outside the camera.
// TODO HERE: ---
// Fetch new data inside the camera
self.fetchNearByEstablishments(newLocationOfCamera)
}
@objc func didDragMap(_ gestureRecognizer: UIPanGestureRecognizer) {
self.hideBottomInfo()
// Fetch new annotations with throttle
self.timer?.invalidate()
self.timer = Timer.scheduledTimer(timeInterval: 1.5, target: self, selector: #selector(self.throttleDone), userInfo: nil, repeats: false)
}
我觉得这很容易,但我在这里找不到任何答案,所以和谷歌。谢谢您!