作者:天空的鸟儿飞 | 来源:互联网 | 2022-12-26 12:31
我有一个纬度数组和另一个经度数组,我添加到CLLocationCoordinate2D类型的数组.然后我使用新数组来注释地图上的多个点.一些,或大多数,甚至所有注释都在地图上显示但是当我放大(是的,放大IN)时,一些注释消失,然后回来,或者不.关于如何让它们全部可见的任何想法?这是我在缩小时所期望的行为,而不是.
这是我用于上述内容的代码.
import UIKit
import MapKit
import CoreLocation
class MultiMapVC: UIViewController, CLLocationManagerDelegate {
@IBOutlet weak var multiEventMap: MKMapView!
var latDouble = Double()
var lOngDouble= Double()
let manager = CLLocationManager()
var receivedArrayOfLats = [Double]()
var receivedArrayOfLOngs= [Double]()
var locatiOns= [CLLocationCoordinate2D]()
func locationManager(_ manager: CLLocationManager, didUpdateLocations uLocation: [CLLocation]) {
let userLocation = uLocation[0]
let span:MKCoordinateSpan = MKCoordinateSpanMake(0.3, 0.3)
let usersLocation = userLocation.coordinate
let region:MKCoordinateRegion = MKCoordinateRegionMake(usersLocation, span)
multiEventMap.setRegion(region, animated: true)
manager.distanceFilter = 1000
self.multiEventMap.showsUserLocation = true
}
func multiPoint() {
var coordinateArray: [CLLocationCoordinate2D] = []
print ("Received Longitude Count = \(receivedArrayOfLongs.count)")
print ("Received Latitude Count = \(receivedArrayOfLats.count)")
if receivedArrayOfLats.count == receivedArrayOfLongs.count {
for i in 0 ..
}
1> Leszek Szary..:
NiltiakSivad的解决方案有效,但它恢复到旧的iOS 10外观.如果你想为iOS 11保留新的iOS 11气球标记,并且只使用旧的iOS版本,那么你可以实现如下的委托方法:
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
let reuseIdentifier = "annotationView"
var view = mapView.dequeueReusableAnnotationView(withIdentifier: reuseIdentifier)
if #available(iOS 11.0, *) {
if view == nil {
view = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: reuseIdentifier)
}
view?.displayPriority = .required
} else {
if view == nil {
view = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseIdentifier)
}
}
view?.annotation = annotation
view?.canShowCallout = true
return view
}
2> 小智..:
我遇到了类似的问题。我最好的猜测是,它与iOS 11如何检测到销钉冲突有关。实施自定义注释视图或还原为使用iOS 10针对我来说解决了这个问题。
例如,实现以下内容应该可以修复您的代码:
class MultiMapVC: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
mapView.delegate = self
}
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
guard let annotation = annotation as? MKPointAnnotation else { return nil }
let identifier = "pin-marker"
var view: MKAnnotationView
if let dequeuedView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier) as? MKPinAnnotationView {
dequeuedView.annotation = annotation
view = dequeuedView
} else {
view = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
}
return view
}
}
如果这不起作用,则有一个displayPriority
值得研究的属性,因为它有助于确定何时应隐藏/显示不同缩放级别的引脚。有关更多信息,请访问https://developer.apple.com/documentation/mapkit/mkannotationview/2867298-displaypriority
希望这可以帮助。