有没有办法在屏幕上检测用户是否双击标记? 或者如果他们点按并按住屏幕一段时间?
Mapbox具有以下返回true的方法,该方法用于显示有关当前位置/标记的信息。检查用户是否点击此白色部分或双击当前标记的最佳方法是什么?
提前谢谢!
/* Tapping the marker */
func mapView(mapView: MGLMapView!, annotationCanShowCallout annotation: MGLAnnotation!) -> Bool {
return true
/*THIS WHERE THE TAP IS BEING RECOGNIZED,
return true here allows the information about the current marker (name and address)*/
}//eom
import UIKit
import MapboxGL
import CoreLocation
class ViewController: UIViewController, MGLMapViewDelegate , CLLocationManagerDelegate {
private var currLocLatitude:CLLocationDegrees = 28.43173
private var currLocLongitude:CLLocationDegrees = -81.4704
private var currLocTitle:String = "Tommy Bahama"
private var currLocSubtitle:String = "9101 International Drive #1200, Orlando, FL 32819, United States"
var mapView:MGLMapView!
private var MapBoxAccessToken = "pk.eyJ1IjoiZGFya2ZhZGVyIiwiYSI6IlplV6hfR3MpfQ.pPEz732qS8g0WEScdItakg"
/* defining the marker from MyAnnotation.swift */
func mapView(mapView: MGLMapView!, symbolNameForAnnotation annotation: MGLAnnotation!) -> String! {
return "secondary_marker"
}
/**/
override func viewDidLoad() {
super.viewDidLoad()
self.createMapBoxMap()
}//eom
/**/
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*************** MapBox Methods **********/
//method creating the mapbox map
private func createMapBoxMap(){
//type of map style
self.mapView = MGLMapView(frame: view.bounds, accessToken: MapBoxAccessToken)
self.mapView.autoresizingMask = .FlexibleWidth | .FlexibleHeight
//setting the map's center coordinate
self.mapView.setCenterCoordinate(CLLocationCoordinate2D(latitude: self.currLocLatitude, longitude: self.currLocLongitude),
zoomLevel: 12, animated: true)
self.view.addSubview(mapView)
/*define the marker and its coordinates, title, and subtitle:*/
self.mapView.delegate = self // Set the delegate property of our map view to self after instantiating it.
// Declare the marker `ellipse` and set its coordinates, title, and subtitle
let ellipse = MyAnnotation(location: CLLocationCoordinate2D(latitude: self.currLocLatitude, longitude: self.currLocLongitude),
title: self.currLocTitle, subtitle: self.currLocSubtitle)
self.mapView.addAnnotation(ellipse) // Add marker `ellipse` to the map
self.mapView.showsUserLocation = false //shows the current positions
}//eom
/* Tapping the marker */
func mapView(mapView: MGLMapView!, annotationCanShowCallout annotation: MGLAnnotation!) -> Bool {
return true
/*THIS WHERE THE TAP IS BEING RECOGNIZED,
return true here allows the information about the current marker (name and address)*/
}//eom
}//eoc
答案 0 :(得分:0)
要检测白色部分(注释的标注)上的用户触摸,您可以使用以下方法:
func mapView(mapView: MGLMapView, tapOnCalloutForAnnotation annotation: MGLAnnotation) {
print("tap on callout")
}
有关详细信息,请参阅mapbox文档:https://www.mapbox.com/ios-sdk/api/3.0.0/Protocols/MGLMapViewDelegate.html#//api/name/mapView:tapOnCalloutForAnnotation: