3

Google マップ ビュー全体の 1 つに UIGestureRecognizer を追加しようとしています。

マップ(マーカーではなく)に触れたときに通知を受け取りたいのですが、方法がわかりません。私がしたことは、viewDidLoad内でこれです:

UITapGestureRecognizer* tapRec = [[UITapGestureRecognizer alloc]
                                  initWithTarget:self action:@selector(didTapMap:)];
[mapView_ addGestureRecognizer:tapRec];

およびviewDidLoadの外側:

- (void)didTapMap:(UITapGestureRecognizer *)recognizer {
    NSLog(@"Touched map");
}

しかし、この方法は機能せず、コンソール ウィンドウに何も出力しません。

私を助けて、それを行う方法を教えてください

4

4 に答える 4

17

必要なものはすでにマップのデリゲートの一部だと思います

 /**
 * Called after a tap gesture at a particular coordinate, but only if a marker
 * was not tapped.  This is called before deselecting any currently selected
 * marker (the implicit action for tapping on the map).
 */
- (void)mapView:(GMSMapView *)mapView
    didTapAtCoordinate:(CLLocationCoordinate2D)coordinate;

そのデリゲートには他のメソッドがあります。それらも見てください。

Swift には次の関数を使用します。

func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) 
于 2015-03-19T12:07:03.817 に答える