大佬教程收集整理的这篇文章主要介绍了ios11 MKAnnotation没有显示两个注释,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
import UIKit import MapKit import Firebase class GameViewController: UIViewController { @IBOutlet weak var mapView: MKMapView! fileprivate var LOCATIOns = [CLLOCATIOn]() fileprivate var userLOCATIOns = [(loc: CLLOCATIOn,name: String,team: String)]() fileprivate var userAnnotations = [MKAnnotation]() fileprivate var hasBeenUP = false var ref: FIRDatabaseReference! let uid = FIRAuth.auth()!.currentUser!.uid var timer = Timer() var timeLeft = 0.0 var firstTimer = Timer() var name = "" var team = "" override func viewDidLoad() { super.viewDidLoad() let center = CLLOCATIOnCoordinate2D(latitude: 47.786769,longitude: -20.413634) let region = MKCoordinateRegion(center: center,span: MKCoordinateSpan(latitudeDelta: 0.01,longitudeDelta: 0.01)) self.mapView.setRegion(region,animated: truE) mapView.mapType = .hybrid LOCATIOnManager.startupdatingLOCATIOn() ref = FIRDatabase.database().reference() setupULSending() getMetaInfo() ref.child("realtimeLOCATIOns").observe(FIRDataEventType.value,with: { (snapshot) in self.userLOCATIOns = [] for rest in snapshot.children.allObjects as! [FIRDataSnapshot] { guard let snapshotValue = snapshot.value as? NSDictionary,let snapVal = snapshotValue[rest.key] as? NSDictionary else { break } let name = snapVal["name"] as! String let team = snapVal["team"] as? String ?? "" if let lat = snapVal["lat"] as? Double,let long = snapVal["long"] as? Double { let LOCATIOn = CLLOCATIOn(latitude: lat,longitude: long) self.userLOCATIOns.append((loc: LOCATIOn,name: name,team: team)) }else { } } DispatchQueue.main.async { self.updateUserLOCATIOn() } }) } private lazy var LOCATIOnManager: CLLOCATIOnManager = { let manager = CLLOCATIOnManager() manager.allowsBACkgroundLOCATIOnupdates = true manager.desiredAccuracy = kCLLOCATIOnAccuracyBest manager.delegate = self manager.@R_607_10613@estAlwaysAuthorization() return manager }() func updateUserLOCATIOn() { for an in self.mapView.Annotations { mapView.removeAnnotation(an) } for loc in userLOCATIOns { let Annotation = MKPointAnnotation() Annotation.coordinate = loc.loc.coordinate Annotation.title = loc.name Annotation.subtitle = "local" mapView.addAnnotation(Annotation) } } } // MARK: - CLLOCATIOnManagerDelegate extension GameViewController: CLLOCATIOnManagerDelegate { func LOCATIOnManager(_ manager: CLLOCATIOnManager,didupdateLOCATIOns LOCATIOns: [CLLOCATIOn]) { let LOCATIOn = LOCATIOns.last as! CLLOCATIOn self.LOCATIOns.append(LOCATIOn) } }
func mapView(_ mapView: MKMapView,viewFor Annotation: MKAnnotation) -> MKAnnotationView? { if Annotation is MKUserLOCATIOn { return nil } var view = mapView.dequeueReusableAnnotationView(withIdentifier: "yourIdentifier") if view == nil { view = MKMarkerAnnotationView(Annotation: nil,reusEIDentifier: "yourIdentifier") } view?.displayPriority = .required return view }
以上是大佬教程为你收集整理的ios11 MKAnnotation没有显示两个注释全部内容,希望文章能够帮你解决ios11 MKAnnotation没有显示两个注释所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。