我目前正在寻找一种方法,使路线(MGPLPolyline)可点击,从而使得用户可以Mapbox在两种可能的路径选择。不幸的是,路线标注似乎并没有成为可点击在所有:
虽然我已经设定了正确我MGLMapViewDelegate
此方法:
func mapView(_ mapView: MGLMapView, didSelect annotation: MGLAnnotation)
永远不会调用。
我错过了什么知道每行从MGLPolyline
这是一个MGLAnnotation
的子类(我预计是可点击...)继承。
你可以做到以下几点:
首先,当你创建折线做到以下几点:
let polyline = CustomPolyline(coordinates: &coordinates, count: UInt(coordinates.count))
polyline.title = "" //It does not seem to matter what you set it to.
polyline.color = .darkGray
然后在下面的方法返回false:
func mapView(_ mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool {
// Always allow callouts to popup when annotations are tapped.
print("ran?")
return false
}