2017-09-09 5 views
1

問題を解決するのに手伝ってください。私はGoogleマップで地図の長いクリックを追跡しようとしていますが、できません。私のコードの例を次に示します。Googleマップで長引く

import UIKit 
import GoogleMaps 

class ViewController: UIViewController { 
@IBOutlet var mMap: GMSMapView! 

var longPressRecognizer = UILongPressGestureRecognizer() 

@IBAction func longPress(_ sender: UILongPressGestureRecognizer) { 
    testTextview.text = "You tapped at YES" 
} 

override func viewDidLoad() { 
    super.viewDidLoad() 

longPressRecognizer = UILongPressGestureRecognizer(target: self, 
action: #selector(self.longPress)) 
longPressRecognizer.minimumPressDuration = 0.5 
mMap.addGestureRecognizer(longPressRecognizer) 

mMap.isMyLocationEnabled = true 
mMap.settings.compassButton = true 
mMap.camera = GMSCameraPosition.camera(withLatitude: 54.9044200, 
longitude: 52.3154000, zoom: 15.0) 
} 
} 

このコードを使用することはありません。私はstackoverflow上にあったすべてのメソッドを試したが、何も起こらなかった。 shouldRecognizeSimultaneouslyWithここ

あなたは

を追加、修正するために必要なものである

+0

こんにちはthere-あなたが関数から@IBActionデコレータを削除するとどうなりますか? (@ objcに置き換える必要があるかもしれません)。 – Sparky

+0

このメソッドも動作しません – ildar1989

+0

@ ildar1989これのフィードバック? –

答えて

0

GMSMapViewクラスは異なるジェスチャーのrecognisersがたくさんあるので、あなたのViewControllerに、このメソッドを追加することUIGestureRecognizerDelegate実装を追加必要

extension ViewController : UIGestureRecognizerDelegate 
{ 
    public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool 
    { 
     return true 
    } 
} 

このラインlongPressRecognizer.minimumPressDuration = 0.5

完全なコードの下に

longPressRecognizer.delegate = self 

を追加

import UIKit 
import GoogleMaps 

class ViewController: UIViewController { 
@IBOutlet var mMap: GMSMapView! 

var longPressRecognizer = UILongPressGestureRecognizer() 

@IBAction func longPress(_ sender: UILongPressGestureRecognizer) { 
    testTextview.text = "You tapped at YES" 
} 

override func viewDidLoad() { 
    super.viewDidLoad() 

longPressRecognizer = UILongPressGestureRecognizer(target: self, 
action: #selector(self.longPress)) 
longPressRecognizer.minimumPressDuration = 0.5 
longPressRecognizer.delegate = self 
mMap.addGestureRecognizer(longPressRecognizer) 

mMap.isMyLocationEnabled = true 
mMap.settings.compassButton = true 
mMap.camera = GMSCameraPosition.camera(withLatitude: 54.9044200, 
longitude: 52.3154000, zoom: 15.0) 
} 
} 

extension ViewController : UIGestureRecognizerDelegate 
    { 
     public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool 
     { 
      return true 
     } 
    } 
+1

はい、動作します。あなたは天才です。 – ildar1989

関連する問題