iOS 谷歌地图标记拖动事件

标签 ios google-maps-sdk-ios

我正在使用谷歌地图 SDK 构建一个 iOS 应用程序。当用户执行 longPressAtCoordinate 时,我可以在 map 上添加一些标记。我的问题是,当我尝试拖动标记时,diiLongPressAtCoordinate 在 didBeginDraggingMarker 之前被触发,因此也添加了一个新标记。

-(void)mapView:(GMSMapView *)mapView didBeginDraggingMarker:(GMSMarker *)marker{
        NSLog(@"begin dragging marker");
    }
    - (void)mapView:(GMSMapView *)mapView didLongPressAtCoordinate (CLLocationCoordinate2D)coordinate{
        NSLog(@"did long press at mapview");
    //when user didLongPressAtCoordinate I add a new marker on the map.
    // I want to prevent the execution of this code before the didBeginDraggingMarker method
    }

最佳答案

我通过创建一个名为 isDragging 的 bool 属性并根据标记是否被拖动来更改它的值来解决这个问题。

- (void)mapView:(GMSMapView *)mapView didBeginDraggingMarker:(GMSMarker *)marker
{
    self.isDragging = YES;
}

- (void)mapView:(GMSMapView *)mapView didEndDraggingMarker:(GMSMarker *)marker
{
    self.isDragging = NO;
}

然后,每当检测到长按时,我都会验证是否正在拖动标记:

- (void)mapView:(GMSMapView *)mapView didLongPressAtCoordinate:(CLLocationCoordinate2D)coordinate
{
    if (self.isDragging) {

        return;
    }

    NSLog(@"Long press detected");
}

关于iOS 谷歌地图标记拖动事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27397270/

相关文章:

react-native - Android *和* iOS 移动应用程序的 Google map 1 API key 限制

ios - 有没有办法在解析服务器上安排推送通知?

iphone - Facebook SDK iOS 中的用户未登录错误

ios - 更快地构建用于测试的应用程序

ios - 在动态 (Cocoa Touch) 框架内链接静态库

ios - 使用通用 URL 方案向 Google 导航添加多个站点

iphone - 以编程方式从服务器检索更新的文件

ios - 如何更改事件触发的pickerviews的值

ios - 绘制具有背景色的 GMSPolyline

iphone - 如何在 iOS 的 Google map 上添加按钮?