gpt4 book ai didi

ios - Mapbox 注释标注

转载 作者:行者123 更新时间:2023-11-28 15:45:53 26 4
gpt4 key购买 nike

我最近决定从 Mapkit 改为 Mapbox。我在我的 map 中实现了我的注释,但由于某种原因,当我单击注释时,我的注释标注没有出现。我很困惑,不确定为什么没有出现。希望有人能帮忙!相应的代码如下所示:

import UIKit
import Firebase
import Mapbox

class ViewController: UIViewController, SideBarDelegate, MGLMapViewDelegate {


@IBOutlet weak var mapView: MGLMapView!


//Filtering annotations for sidebar

func sideBarDidSelectButtonAtIndex(_ index: Int) {
mapView.removeAnnotations(mapView.annotations!)

for park in skateparks {

if index == 0 {
addAnnotation(park: park)
}

if index == 1 && park.type == .park {
addAnnotation(park: park)
}

if index == 2 && park.type == .street {
addAnnotation(park: park)
}


}

}

var sideBar: SideBar = SideBar()

var skateparks = [Skatepark]()

let locationsRef = FIRDatabase.database().reference(withPath: "locations")

override func viewDidLoad() {
super.viewDidLoad()


//Location

mapView.delegate = self
mapView.showsUserLocation = true

//Sidebar

sideBar = SideBar(sourceView: self.view, skateItems: ["All Skate Spots", "Skateparks", "Street Skating"])
sideBar.delegate = self


// Passing firebase annotation data

locationsRef.observe(.value, with: { snapshot in
self.skateparks.removeAll()

for item in snapshot.children {
guard let snapshot = item as? FIRDataSnapshot else { continue }

let newSkatepark = Skatepark(snapshot: snapshot)

self.skateparks.append(newSkatepark)

self.addAnnotation(park: newSkatepark)
}
})
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
view.sendSubview(toBack: mapView)
}


func addAnnotation(park: Skatepark) {

let point = MGLPointAnnotation()

point.coordinate = park.coordinate

point.title = park.name

point.subtitle = park.subtitle

mapView.addAnnotation(point)

mapView.selectAnnotation(point, animated: true)

}
}

func mapView(mapView: MGLMapView, viewForAnnotation annotation: MGLAnnotation) -> MGLAnnotationView? {
return nil
}


func mapView(mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool {
return true
}

最佳答案

更新您的 SWIFT 3 函数-:

  func mapView(_ mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool { // Always try to show a callout when an annotation is tapped. return true }


func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {

}

关于ios - Mapbox 注释标注,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43073540/

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