2013-05-30 42 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;