从Google地图iOS中删除标记

jch*_*853 23 mapkit google-maps-markers ios google-maps-sdk-ios

我正在使用故事板和Google地图构建iOS应用程序.使用iOS6

我的应用程序具有在Facebook应用程序中看到的拆分视图导航

在我的左视图中,我选择列表中的项目,该项目具有纬线/长线,并在我的地图上通过以下方法显示

- (void)viewWillAppear:(BOOL)animated

我想在添加另一个标记之前删除此方法中的所有标记(因此地图上只有一个标记),有没有办法做到这一点?下面是我在mapView中添加标记的代码

提前谢谢 - 乔恩

- (void)loadView
{
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:poi.lat
                                                            longitude:poi.lon
                                                                 zoom:15];
    mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];

    mapView.myLocationEnabled = YES;
    self.view = mapView;
    mapView.mapType = kGMSTypeHybrid;

    //Allows you to tap a marker and have camera pan to it
    mapView.delegate = self;
}

-(void)viewWillAppear:(BOOL)animated
{
    GMSMarkerOptions *options = [[GMSMarkerOptions alloc] init];
    options.position = CLLocationCoordinate2DMake(poi.lat, poi.lon);
    options.title =  poi.title;
    options.snippet = poi.description;
    options.icon =  [UIImage imageNamed:@"flag-red.png"];
    [mapView addMarkerWithOptions:options];

    [mapView animateToLocation:options.position];
    [mapView animateToBearing:0];
    [mapView animateToViewingAngle:0];
}
Run Code Online (Sandbox Code Playgroud)

Bas*_*raf 45

删除所有标记

mapView.clear()
Run Code Online (Sandbox Code Playgroud)

删除特定标记

myMarker.map = nil
Run Code Online (Sandbox Code Playgroud)


jtu*_*lla 34

删除所有标记简单:

[self.mapView clear];
Run Code Online (Sandbox Code Playgroud)


iOS*_*248 13

请参阅Google Map文档:适用于iOS的Google Maps SDK

请参阅"删除标记"一节.始终检查此类方法的文档.

  • 虽然这在理论上可以回答这个问题,[但最好](http://meta.stackexchange.com/q/8259)在这里包含答案的基本部分,并提供参考链接. (7认同)
  • 你应该回答这个问题. (6认同)

小智 6

mapView.clear()

// 它将清除 GMSMapView 中的所有标记。