Ios 如何在GMS地图上绘制新标记(已绘制标记)并将其设置为选中?

Ios 如何在GMS地图上绘制新标记(已绘制标记)并将其设置为选中?,ios,objective-c,google-maps,google-maps-api-3,gmsmapview,Ios,Objective C,Google Maps,Google Maps Api 3,Gmsmapview,我正在使用Google Maps iOS SDK,并在marker单击时打开marker info窗口,放置了多个标记。现在我想添加一个新的标记,它还没有绘制在地图上。我有不同位置的列表视图,当用户单击其本地位置之外的任何位置时,他将跳转到所选位置。在此之前,所有工作正常,但位置标记未显示错误消息: 标记设置为selectedMarker,但不属于此地图。忽略 我正在重新绘制选定位置上的所有标记,但它对我不起作用。 是否有任何方法可以打印单个或多个标记并将选定标记设置为默认值 for (int

我正在使用Google Maps iOS SDK,并在marker单击时打开marker info窗口,放置了多个标记。现在我想添加一个新的标记,它还没有绘制在地图上。我有不同位置的列表视图,当用户单击其本地位置之外的任何位置时,他将跳转到所选位置。在此之前,所有工作正常,但位置标记未显示错误消息:

标记设置为selectedMarker,但不属于此地图。忽略

我正在重新绘制选定位置上的所有标记,但它对我不起作用。 是否有任何方法可以打印单个或多个标记并将选定标记设置为默认值

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];
} 
for(int i=0;i<[getdata count];i++)
{
LocationData*getlocation=[getdata objectAtIndex:i];
CLLocationCoordinate2D位置=CLLocationCoordinate2DMake(getlocation.lat,getlocation.lont);
GMSMarker*marker=[GMSMarker marker with position:position];
marker.map=\u mapView;
marker.title=getlocation.name;
marker.snippet=getlocation.description;
marker.flat=是;
marker.icon=[UIImage ImageName:img];
} 

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

用于Obj c

GMSMarker *myMarkerAutomaticSnippet = [[GMSMarker alloc] init];
marker.position = <Your cordinates>;
marker.title = @“Title";
marker.snippet = @"Snippet";
marker.map = _mapView; 
[_mapView setSelectedMarker:marker];
GMSMarker*myMarkerAutomaticSnippet=[[GMSMarker alloc]init];
marker.position=;
marker.title=@“title”;
marker.snippet=@“snippet”;
marker.map=\u mapView;
[_MapViewSetSelectedMarker:marker];
适用于Swift 3.0

let myMarker = GMSMarker()
myMarker.position = <Your cordinates>
myMarker.title = "title"
myMarker.snippet = "snippet"
myMarker.map = _mapView    
_mapView.customMapView.selectedMarker = myMarker 
let myMarker=GMSMarker()
myMarker.position=
myMarker.title=“title”
myMarker.snippet=“snippet”
myMarker.map=\u mapView
_mapView.customMapView.selectedMarker=myMarker

检查地图上不存在的ans@AntonyRaphel标记,我需要同时打印和选择当您使用for循环打印标记时,它始终选择最后打印的最后一个标记。使用此选项,您可以进行选择
[mapView setSelectedMarker:marker];