如何在 GMS 地图上绘制新标记(带有已绘制的标记)并选择设置?

How plot new marker (with already plotted markers) on GMS map and set selected?

我正在使用 Google Maps iOS SDK 并放置了多个带有标记信息的标记 window 单击标记时打开。现在我想添加尚未在地图上绘制的新标记。当用户点击他本地位置以外的任何地方时,我有不同地方的列表视图,他将跳转到所选位置。直到这一切正常,但地点标记未显示并显示错误消息:

Marker set as selectedMarker while not belonging to this map. Ignoring.

我正在重新绘制选定位置上的所有标记,但它对我不起作用。 有什么方法可以绘制单个或多个标记并设置所选标记的默认设置。

for (int i =0; i < [getdata count]; i++)
{
    LocationData *getlocation = [getdata objectAtIndex:i];
    CLLocationCoordinate2D position = CLLocationCoordinate2DMake(getlocation.lat, getlocation.longt);
    GMSMarker *marker = [GMSMarker markerWithPosition:position];
    marker.map = _mapView;
    marker.title = getlocation.name;
    marker.snippet = getlocation.disciption;
    marker.flat = YES;
    marker.icon = [UIImage imageNamed:img];
} 

您可以触发位置选择方法以在地图上默认选择的情况下绘制单个新标记:

对于对象 c

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

为Swift3.0

let myMarker = GMSMarker()
myMarker.position = <Your cordinates>
myMarker.title = "title"
myMarker.snippet = "snippet"
myMarker.map = _mapView    
_mapView.customMapView.selectedMarker = myMarker