【问题标题】:iOS Google Maps Marker drag eventiOS Google Maps Marker 拖动事件
【发布时间】:2015-02-08 10:14:45
【问题描述】:

我正在使用谷歌地图 SDK 构建一个 iOS 应用程序。当用户执行 longPressAtCoordinate 时,我可以在地图上添加一些标记。我的问题是,当我尝试拖动标记时, 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
    }

【问题讨论】:

    标签: ios google-maps-sdk-ios


    【解决方案1】:

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

    - (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");
    }
    

    【讨论】:

      猜你喜欢
      • 2014-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-27
      • 2019-06-02
      • 1970-01-01
      • 2013-01-24
      相关资源
      最近更新 更多