我是iOS开发和mapbox的新手,很抱歉,如果问题听起来很愚蠢,但我在任何地方都找不到答案。我有一张地图和注解。当用户触摸并持有注释时,我想显示一些其他信息(长按压手势)。我有一个长时间的按压手势,但是找到了找到被触摸的注释的方法,或者至少找到了它的索引。到目前为止,我有这样的想法:
class eventsMapController: UIViewController, MGLMapViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
mapView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
// Set the map's bounds to Oslo 59.920269,10.71167
//let bounds = MGLCoordinateBounds(sw: CLLocationCoordinate2D(latitude: 59.925861, longitude: 10.712185),
// ne: CLLocationCoordinate2D(latitude: 59.889798, longitude: 10.794754))
view.addSubview(mapView)
// Set the map view‘s delegate property
mapView.delegate = self
let myGesture = UILongPressGestureRecognizer(target: self, action: #selector(eventsMapController.testLongGesture))
myGesture.minimumPressDuration = 0.8
mapView.addGestureRecognizer(myGesture)
}
func testLongGesture(long: UILongPressGestureRecognizer){
if long.state == .Began{
print("begin", long)
}
}
}我在添加这样的注解
let pointAnotation = MGLPointAnnotation()
pointAnotation.coordinate = CLLocationCoordinate2DMake(event.lat, event.lng)
pointAnotation.title = name
pointAnotation.subtitle = headline
self.mapView.addAnnotation(pointAnotation)请帮帮我,我花了很多时间想办法弄清楚。
发布于 2016-06-11 21:01:25
我想我要尝试的第一件事是实现委托方法mapView(_:didSelectAnnotation:)。我不确定在发生长新闻时是否会调用它,但如果是的话,通过告诉您要使用哪个注释,会使事情变得相对简单。
如果没有,您可能需要执行如下操作:
CLLocationCoordinate2D。https://stackoverflow.com/questions/37748995
复制相似问题