Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

which marker is tapped in Google Maps SDK ios?

I have many markers in GMSMapView. I want to know which marker is tapped. I know that there is - (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker delegate. But my problem is when i tap any marker, i will show different information for every marker in infoWindow. So, i must know which marker is tapped.How can i do this?

like image 335
Ayubxon Ubaydullayev Avatar asked Mar 19 '23 20:03

Ayubxon Ubaydullayev


2 Answers

When you create the marker, set its userData property to an instance of your own class which stores data about the marker.

Then in didTapMarker, you can get out the userData property, cast it to your own type, and then extract the details you need.

like image 157
Saxon Druce Avatar answered Mar 28 '23 09:03

Saxon Druce


You can set the accessibilityLabel property of marker during its creation from your data.

For example you are creating the markers from an array of objects then set the marker.accessibilityLabel of each marker as its position in your array so when user is going to tap on any marker, just find its accessibilityLabel and so find the data from array at this position.

like image 45
iHulk Avatar answered Mar 28 '23 10:03

iHulk