如何以编程方式点击 ios google 地图标记或显示标记的信息 window?

How to tap on ios google map marker programatically or show info window of marker?

我正在使用带有多个标记的 Google 地图 iOS SDK,它将在标记点击时显示标记信息 window。下面的代码适用于多个标记和按预期显示在地图视图中的标记。它还会在标记点击时显示标记信息 window,并在点击时更改标记图标。

-(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;    
} 

现在我想以编程方式触发点击标记或在标记上显示信息 window。

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

以上代码对我不起作用。它只是移动到标记的位置不显示信息 window。有什么方法可以通过编程方式单击标记并显示信息 window?

必须提供标记地图

对于对象 c

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


[myCustomMapView setSelectedMarker:marker];

为Swift3.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