从谷歌地图 iOS 中删除标记

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16067575/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 23:13:55  来源:igfitidea点击:

Remove markers from google maps iOS

iosmapkitgoogle-maps-markersgoogle-maps-sdk-ios

提问by jchri853

I am building an iOS app using storyboards and Google Maps. Using iOS6

我正在使用故事板和谷歌地图构建一个 iOS 应用程序。使用 iOS6

My application features the split view navigation as seen in the facebook app

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

On my left view I am selecting an item in a list which has lat/long cords and showing it on my map on the following method

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

- (void)viewWillAppear:(BOOL)animated

- (void)viewWillAppear:(BOOL)animated

I would like to remove all markers in this method before I add another one (so only one marker is on the map), is there a way to do this? Below is my code to add a marker to the mapView

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

Thanks in advance - Jon

提前致谢 - 乔恩

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

采纳答案by iOSGuru248

Please refer to the Google Map documentation: Google Maps SDK for iOS

请参考谷歌地图文档:Google Maps SDK for iOS

Please refer to the section title "Remove a marker". Always check documentation for such methods.

请参阅“移除标记”一节。始终检查此类方法的文档。

回答by Bassant Ashraf

To remove all markers

删除所有标记

mapView.clear()

To remove a specific marker

删除特定标记

myMarker.map = nil

回答by jturolla

To remove all markers simple do:

要删除所有标记,请执行以下操作:

[self.mapView clear];

回答by Hitesh Chauhan

mapView.clear()

mapView.clear()

// It will clear all markers from GMSMapView.

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

回答by Mahadhi Hassan Chowdhury

To remove a single marker

删除单个标记

yourMarkerName.map = nil

yourMarkerName.map = nil

To remove all markers

删除所有标记

yourMapViewName.clear()

yourMapViewName.clear()

回答by maryam chaharsooghi

mapView.clear() is not a good idea . because The Places SDK for iOS enforces a default limit of 1,000 requests per 24 hour period.(If your app exceeds the limit, the app will start failing. Verify your identity to get 150,000 requests per 24 hour period.) whit mapView.clear() the requests increase . the best way is clear each marker and polylines .

mapView.clear() 不是一个好主意。因为 iOS 版 Places SDK 强制执行每 24 小时 1,000 个请求的默认限制。(如果您的应用程序超过限制,应用程序将开始失败。验证您的身份以每 24 小时获得 150,000 个请求。) whit mapView.clear( ) 请求增加。最好的方法是清除每个标记和折线。