【问题标题】:How plot new marker (with already plotted markers) on GMS map and set selected?如何在 GMS 地图上绘制新标记(已绘制标记)并选择?
【发布时间】:2017-07-24 09:41:34
【问题描述】:

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

标记设置为 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];
} 

【问题讨论】:

  • @AntonyRapel 标记不在地图上,我需要同时绘制和选择
  • 当你用 for 循环绘制标记时,它总是选择最后绘制的最后一个标记。有了这个你可以选择[mapView setSelectedMarker:marker];

标签: ios objective-c google-maps google-maps-api-3 gmsmapview


【解决方案1】:

您可以触发位置选择方法以在地图上默认选择单个新标记:

对于对象

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

对于 Swift 3.0

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-09
    • 2014-03-07
    • 1970-01-01
    相关资源
    最近更新 更多