【问题标题】:GMSMapView touchesbegan fired only onceGMSMapView touchesbegan 仅触发一次
【发布时间】:2013-05-30 17:44:56
【问题描述】:
我正在尝试扩展 GMSMapView 以创建一些集群功能,我需要检测用户何时移动地图以禁用集群渲染并在完成后重新启用它。
我覆盖了 touchesbegan 和 touchesended,但 touchesbegan 只调用了一次。
覆盖 hittest 后,我可以看到 GMSVectorMapView 处理 GMSMapView 触摸,如果我更改此函数的返回,地图不会移动。
当用户与地图交互时,是否有任何方法可以捕获此事件或执行某些操作。
最好的问候,
马龙·皮娜·托贾尔
【问题讨论】:
标签:
ios
google-maps
google-maps-sdk-ios
【解决方案1】:
我不确定我是否完全理解您需要检测哪些触摸或为什么/如何检测它们。但是,由于 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 的手势识别器属性中。我确保使用选择器方法didPan:将目标设置为self
// 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
}
【解决方案2】:
最新的更新是谷歌地图中有一个委托方法
- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate;