0
私はUILongPressGestureRecognizerでマーカーを追加したいが、私のコードはうまくいかなかった。この方法はあまりにも動作しますしないUILongPressGestureRecognizerでGoogleマップにマーカーを追加するswift3
func setupGesture() {
let longPressRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(action))
longPressRecognizer.minimumPressDuration = 1.0
mapView.addGestureRecognizer(longPressRecognizer)
}
func action(recognizer: UILongPressGestureRecognizer) {
if (recognizer.state == .ended) {
DispatchQueue.main.async {
let longPressPoint = recognizer.location(in: mapView)
let coordinate = self.mapView.projection.coordinate(for: longPressPoint)
let marker = GMSMarker(position: coordinate)
marker.title = "Hello World"
marker.map = mapView
}
}
}
..
extension MapViewController: GMSMapViewDelegate {
func mapView(_ mapView: GMSMapView, didLongPressAt coordinate: CLLocationCoordinate2D) {
DispatchQueue.main.async {
let marker = GMSMarker(position: coordinate)
marker.title = "Hello World"
marker.map = mapView
}
}
}
didLongTapAtデリゲートの機能を使用し、 'DispatchQueue.main.async {//あなたのマーカーcode' –
はい、私はメインスレッドでそれをしましたが、マーカーは表示されません –