Marker events and gestures

When specific advanced marker properties are set, you can monitor marker events such as taps and gestures . If a marker is tapped, one can see additional information such as a marker title or snippet. One can also move draggable markers using a long press gesture.

Respond to marker events

You can respond to marker events by adding the GMSMapViewDelegate protocol to your view and implementing the corresponding callback. This example identifies the title and snippet for a selected marker.

Swift

 // MARK: GMSMapViewDelegate 
 func 
  
 mapView 
 ( 
 _ 
  
 mapView 
 : 
  
 GMSMapView 
 , 
  
 didTap 
  
 marker 
 : 
  
 GMSMarker 
 ) 
  
 -> 
  
 Bool 
  
 { 
  
 if 
  
 let 
  
 title 
  
 = 
  
 marker 
 . 
 title 
  
 { 
  
 if 
  
 let 
  
 snippet 
  
 = 
  
 marker 
 . 
 snippet 
  
 { 
  
 print 
 ( 
 "marker title: 
 \( 
 title 
 ) 
 : snippet: 
 \( 
 snippet 
 ) 
 " 
 ) 
  
 } 
  
 } 
  
 return 
  
 true 
 } 

Objective-C

 // MARK: GMSMapViewDelegate 
 - 
 ( 
 BOOL 
 ) 
 mapView: 
 ( 
 GMSMapView 
  
 * 
 ) 
 mapView 
  
 didTapMarker: 
 ( 
 GMSMarker 
  
 * 
 ) 
 marker 
  
 { 
  
 if 
  
 ( 
 marker 
 . 
 title 
  
 && 
  
 marker 
 . 
 snippet 
 ) 
  
 { 
  
 NSLog 
 ( 
 @"marker with title:%@ snippet: %@" 
 , 
  
 marker 
 . 
 title 
 , 
  
 marker 
 . 
 snippet 
 ) 
  
 } 
  
 return 
  
 YES 
 ; 
 } 

Control marker visibility by map zoom level

To control the visibility of GMSMarker , implement the GMSMapViewDelegate protocol and add a condition to set GMSMarker.map .

Swift

 // MARK: GMSMapViewDelegate 
 func 
  
 mapView 
 ( 
 _ 
  
 mapView 
 : 
  
 GMSMapView 
 , 
  
 didChange 
  
 position 
 : 
  
 GMSCameraPosition 
 ) 
  
 { 
  
 marker 
 . 
 map 
  
 = 
  
 position 
 . 
 zoom 
  
 >= 
  
 14 
  
 ? 
  
 mapView 
  
 : 
  
 nil 
 } 

Objective-C

 // MARK: GMSMapViewDelegate 
 - 
 ( 
 void 
 ) 
 mapView: 
 ( 
 GMSMapView 
  
 * 
 ) 
 mapView 
  
 didChangeCameraPosition: 
 ( 
 GMSCameraPosition 
  
 * 
 ) 
 position 
  
 { 
  
 marker 
 . 
 map 
  
 = 
  
 position 
 . 
 zoom 
  
 >= 
  
 14 
  
 ? 
  
 mapView 
  
 : 
  
 nil 
 ; 
 } 

Make a marker draggable

When you enable the draggable property users can drag markers on the map with a long press gesture. To make a marker draggable, set the GMSMarker.draggable property to true.

Swift

 marker 
 . 
 draggable 
  
 = 
  
 true 

Objective-C

 marker 
 . 
 draggable 
  
 = 
  
 YES 
 ; 
Design a Mobile Site
View Site in Mobile | Classic
Share by: