2013-05-30 121 views
7

我試圖擴展GMSMapView以創建一些集羣功能,我需要檢測用戶星星移動地圖時禁用集羣渲染並在完成時重新啓用它。GMSMapView touchesbegan只觸發一次

我override了touchesbegan和touchesended,但touchesbegan只被調用一次。 覆蓋hittest後,我能夠看到GMSVectorMapView處理GMSMapView觸摸,如果我更改此函數的返回,地圖不會移動。

有沒有什麼辦法來捕捉這個事件,或者在用戶與地圖交互時做出一些動作。

最好的問候, 馬龍翩Tojal

回答

10

我不知道我完全理解什麼觸動你需要檢測或者爲什麼/如何需要檢測它們。但是,由於touchesbegan,我在GMSMapView之上檢測用戶平移手勢的類似問題:只調用一次。

我有我自己的「當前位置」按鈕,讓用戶在地圖上開/關切換地圖。我需要找出用戶何時「平移」地圖而不中斷地圖接收的平移(我仍然希望地圖也能平移)。

首先,我創建的地圖:

// Creates Map centered at current location 
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:theLocationManager.location.coordinate.latitude 
                 Longitude:theLocationManager.location.coordinate.longitude 
                  zoom:15]; 
theMapView = [GMSMapView mapWithFrame:CGRectZero camera:camera]; 
theMapView.myLocationEnabled = YES; 
theMapView.delegate = self; 
theMapView.camera = camera; 
self.view = theMapView; 

然後創建了一個平移手勢識別,並將其加入到theMapView的手勢識別屬性。我就確定了目標與選擇方法設置爲selfdidPan:

// Watch for pan 
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget: self action:@selector(didPan:)]; 
theMapView.gestureRecognizers = @[panRecognizer]; 

最後,在同一個主文件,我實現了didPan:方法反應,當用戶鍋:

- (void) didPan:(UIPanGestureRecognizer*) gestureRecognizer 
{ 
    NSLog(@"DID PAN"); 
    // React here to user's pan 
} 
+0

其真正完美答案。謝謝+1 –

1

最新更新是否有一個在Google地圖中的代表方法

- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate;