从Google Maps iOS删除标记

问题描述 投票:23回答:7

我正在使用情节提要和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];
}
ios mapkit google-maps-markers google-maps-sdk-ios
7个回答
13
投票

请参阅Google Map文档:Google Maps SDK for iOS

请参阅标题为“删除标记”的小节。始终检查文档以了解此类方法。


46
投票

删除所有标记

mapView.clear()

删除特定标记

myMarker.map = nil

34
投票

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

[self.mapView clear];

4
投票

mapView.clear()

//将从GMSMapView清除所有标记。


1
投票

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


0
投票

要删除单个标记

yourMarkerName.map =无

要删除所有标记

yourMapViewName.clear()


-2
投票

简单

快速

var mapView = GMSMapView() // Global Declaration

self.mapView.clear() // clear the markers

首先,清除地图视图图标并在其后设置标记。

在使用任何循环之前,它应该写在地图视图标记固定功能上。

© www.soinside.com 2019 - 2024. All rights reserved.