How to click on ios google map marker programmatically or show marker info window?

I am working with the Google Maps iOS SDK with several markers that will display a marker info window on a marker. Below code works for several markers and markers displayed in map view as expected. It also displays a marker information window when a marker is clicked and changes the marker icon when clicked.

-(UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)imarker { UIView *infowindow = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 90, 45)]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 90, 45)]; [label setFont:[UIFont fontWithName:@"TrebuchetMS-Bold" size:22]]; infowindow.layer.cornerRadius = 5; infowindow.layer.borderWidth = 2; label.textAlignment = NSTextAlignmentCenter; label.text = @"Test"; label.textColor=[UIColor greenColor]; infowindow.backgroundColor=[UIColor whiteColor]; [infowindow addSubview:label]; return infowindow; } 

Now I want to invoke a soft click on the marker or show the info window on the marker.

 marker = [GMSMarker markerWithPosition:position]; marker.title = @"Name"; marker.snippet = @"Test"; [self mapView:_mapView didTapMarker:marker]; [_mapView setSelectedMarker:marker]; 

Above code does not work for me. It simply moves to the marker location, does not show the info window. Is there a way to programmatically click a marker and show the info window?

+5
source share
1 answer

Giving a card to a marker is important

For obj c

 GMSMarker *myMarkerAutomaticSnippet = [[GMSMarker alloc] init]; marker.position = <Your cordinates>; marker.title = @"my Title"; marker.snippet = @"my Snippet"; marker.map = myCustomMapView; [myCustomMapView setSelectedMarker:marker]; 

For Swift 3.0

  let myMarker = GMSMarker() myMarker.position = CLLocationCoordinate2DMake(80.0, 80.0) myMarker.title = "marker title" myMarker.snippet = "marker snippet" myMarker.map = customMap // Here custom map is your GMSMapView customMap.customMapView.selectedMarker = myMarker // This line is important which opens the snippet 
+4
source

Source: https://habr.com/ru/post/1261716/


All Articles