Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Google map - How to know when user begins or stop drag map

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?

like image 555
tequilar Tomsk Avatar asked Feb 21 '14 09:02

tequilar Tomsk


People also ask

How do I drag a location on Google Maps?

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.


3 Answers

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.

like image 91
Peter Theill Avatar answered Sep 26 '22 19:09

Peter Theill


Swift 4:

func mapView(_ mapView: GMSMapView, willMove gesture: Bool) {     if (gesture){         print("dragged")     } } 
like image 23
realtimez Avatar answered Sep 24 '22 19:09

realtimez


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.

like image 25
Lefteris Avatar answered Sep 23 '22 19:09

Lefteris