Handle tap events Stay organized with collections Save and categorize content based on your preferences.
AI-generated Key Takeaways
Learn how to make data features on your map clickable and respond to tap events.
Utilize tap events to reveal attribute information, such as displaying the 'acres' value for a park when tapped.
This functionality applies to dataset features, and the provided examples use a dataset of parks in New York City.
Invisible features (polygons with insufficient alpha) will not trigger tap events.
Code samples demonstrate how to implement this feature for Android, iOS, and JavaScript platforms.
Make data features respond to tap events, and use the event todisplay the value of an attribute for the tapped feature.

Handle dataset layer events
This example shows data features for a dataset with IDYOUR_DATASET_ID, and implements thedelegate function to display thevalue of an attribute for the tapped feature.
In this example, the dataset showsparks in New York City.For each dataset feature, corresponding to a park, the dataset contains anattribute namedacres containing the surface area of the park. For a tappedpark, display the value of theacres attribute.
Swift
classSampleViewController:UIViewController{privatelazyvarmapView:GMSMapView=GMSMapView(frame:.zero,mapID:GMSMapID(identifier:"YOUR_MAP_ID"),camera:GMSCameraPosition(latitude:40.7,longitude:-74,zoom:12))// Set default styles.view=mapViewletstyle=FeatureStyle(fill:.green.withAlphaComponent(0.5),stroke:.green,strokeWidth:2)mapView.datasetFeatureLayer(of:"YOUR_DATASET_ID").style={_instyle}mapView.delegate=self}extensionSampleViewController:GMSMapViewDelegate{funcmapView(_mapView:GMSMapView,didTapfeatures:[Feature],infeatureLayer:FeatureLayer<Feature>,atLocation:CLLocationCoordinate2D){lettoast=UIAlertController(title:"Area of park",message:(features.compactMap{($0as?DatasetFeature)?.datasetAttributes["acres"]}).joined(separator:", "),preferredStyle:.alert)present(toast,animated:true,completion:nil)}}
Objective-C
@interfaceSampleViewController:UIViewController<GMSMapViewDelegate>@end@implementationSampleViewController-(void)loadView{GMSMapView*mapView=[GMSMapViewmapWithFrame:CGRectZeromapID:[GMSMapIDmapIDWithIdentifier:@"YOUR_MAP_ID"]camera:[GMSCameraPositioncameraWithLatitude:40.7longitude:-74zoom:12]];mapView.delegete=self;// Set default styles.GMSFeatureStyle*style=[GMSFeatureStylestyleWithFillColor:[[UIColorgreenColor]colorWithAlphaComponent:0.5]strokeColor:[UIColorgreenColor]strokeWidth:2.0];[_mapViewdatasetFeatureLayerOfDatasetID:@"YOUR_DATASET_ID"].style=^(GMSDatasetFeature*feature){returnstyle;};self.view=mapView;}-(void)mapView:(GMSMapView*)mapViewdidTapFeatures:(NSArray<id<GMSFeature>>*)featuresinFeatureLayer:(GMSFeatureLayer*)featureLayeratLocation:(CLLocationCoordinate2D)location{NSMutableArray<NSString*>*parkAreas=[NSMutableArrayarray];for(id<GMSFeature>featureinfeatures){if(![featureisKindOfClass:[GMSDatasetFeatureclass]]){continue;}NSString*nameDefinedInDataset=((GMSDatasetFeature*)feature).datasetAttributes[@"acres"];[parkAreasaddObject:nameDefinedInDataset];}UIAlertController*toast=[UIAlertControlleralertControllerWithTitle:@"Area of park"message:[parkAreascomponentsJoinedByString:@", "]preferredStyle:UIAlertControllerStyleAlert];[selfpresentViewController:toastanimated:YEScompletion:nil];}@end
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-11-21 UTC.