如何在GMSMapView上实现GMSMarker拖放?

时间:2021-07-18 14:27:25
  1. I set the marker on google map but when i drag it's all of map are drag.

    我在谷歌地图上设置了标记,但是当我拖动它时,所有的地图都是拖动的。

  2. I want drag marker when click and drag on it's

    我想要点击并拖动它时拖动标记

  3. and drag map when click and drag outside marker.

    单击并拖动标记外拖动地图。

this is my code

这是我的代码

self.camera = [GMSCameraPosition cameraWithLatitude:-33.86 longitude:151.20 zoom:6 bearing:0 viewingAngle:0];
self.Map = [GMSMapView mapWithFrame:self.MapView.bounds camera:self.camera];
self.Map.myLocationEnabled = YES;
self.Map.delegate = self;

GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = self.camera.target;
marker.draggable = YES;
marker.title = @"Sydney";
marker.snippet = @"Australia";
marker.map = self.Map;
marker.icon = [GMSMarker markerImageWithColor:[UIColor blueColor]];
marker.appearAnimation = kGMSMarkerAnimationPop;

[self.MapView addSubview:self.Map];

and this is event on drag drop

这是拖拽事件

- (void) mapView:(GMSMapView *)mapView didBeginDraggingMarker:(GMSMarker *)marker
{

}

- (void) mapView:(GMSMapView *)mapView didEndDraggingMarker:(GMSMarker *)marker
{

}

- (void) mapView:(GMSMapView *)mapView didDragMarker:(GMSMarker *)marker
{

}

when i run my app and debug all above event not work. but event click on marker work well.

当我运行我的应用程序并调试所有上述事件不起作用。但事件点击标记工作很好。

how i implement drag drop ?

我如何实现拖放?

1 个解决方案

#1


12  

You have to press-and-hold on the marker before it will begin dragging. I thought it wasn't working either until someone pointed this out... really needs to be in Google's documentation.

您必须在标记开始拖动之前按住该标记。我认为它不起作用,直到有人指出这一点......真的需要在谷歌的文档中。

#1


12  

You have to press-and-hold on the marker before it will begin dragging. I thought it wasn't working either until someone pointed this out... really needs to be in Google's documentation.

您必须在标记开始拖动之前按住该标记。我认为它不起作用,直到有人指出这一点......真的需要在谷歌的文档中。