I'm developing with Google map SDK 6.1
.I want to know when user begin drag or stop drag the map, I just found 2 delegate function : didChangeCameraPosition
and idleAtCameraPosition
. Is there a way to catch when user begin or stop drag the map?
Open or create a map. Click an existing place on the map. In the bottom right of the box that appears, use the icons to make changes. Move place: Drag the feature on the map.
To detect if the user dragged the map I think it's better to use this delegate method
Obj-C
- (void)mapView:(GMSMapView *)mapView willMove:(BOOL)gesture
Swift
func mapView(_ mapView: GMSMapView, willMove gesture: Bool)
and check whether gesture
argument is true
or not.
The didChangeCameraPosition
is called, as mentioned, many times but since it's also called by both setting the map center from code and as a result of a gesture you can't really see the difference in that method alone.
Swift 4:
func mapView(_ mapView: GMSMapView, willMove gesture: Bool) { if (gesture){ print("dragged") } }
From the documentation :
- (void) mapView:(GMSMapView *)mapView idleAtCameraPosition:(GMSCameraPosition *)position
Called when the map becomes idle, after any outstanding gestures or animations have completed (or after the camera has been explicitly set).
So with this delegate you can capture when the user stopped dragging the mapView.
To get notified when the user did start dragging, just use the other delegate you have pointed out:
- (void) mapView:(GMSMapView *)mapView didChangeCameraPosition:(GMSCameraPosition *)position
Called repeatedly during any animations or gestures on the map (or once, if the camera is explicitly set).
This may not be called for all intermediate camera positions. It is always called for the final position of an animation or gesture.
I'm not sure what is confusing you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With