【问题标题】:Remove markers from google maps iOS从谷歌地图iOS中删除标记
【发布时间】:2013-04-10 15:50:40
【问题描述】:

我正在使用故事板和 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


    【解决方案1】:

    删除所有标记

    mapView.clear()
    

    删除特定标记

    myMarker.map = nil
    

    【讨论】:

      【解决方案2】:

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

      [self.mapView clear];
      

      【讨论】:

      • 这个删除标记和地图的所有项目,更好的解决方案?
      • 请注意,这会清除地图上的所有内容。因此,如果您有标记,也许还有折线,它也会清除它们。如果两者都喜欢,则需要将所有标记放在一个数组中,循环遍历数组并清除每个标记。这将保留您的折线。
      【解决方案3】:

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

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

      【讨论】:

      • 我正在使用 GMSMapView - Google 地图类。除非您可以将这些方法应用于谷歌地图?
      • 哈哈 NP,在文档中错过了,感谢您抽出宝贵时间帮助我!
      • 你应该回答这个问题。
      • 虽然理论上这可以回答这个问题,it would be preferable 在这里包含答案的基本部分,并提供链接以供参考。
      • @iOSGuru248 如果我只想删除标记而不是折线怎么办。这也会删除绘制的路径?
      【解决方案4】:

      mapView.clear()

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

      【讨论】:

        【解决方案5】:

        删除单个标记

        yourMarkerName.map = nil

        删除所有标记

        yourMapViewName.clear()

        【讨论】:

          【解决方案6】:

          如果您只想删除一组标记中的一个标记,这有点棘手。

           let marker = GMSMarker(position: coordinate) //
            marker.icon = UIImage(named: "ic_pin_marker")
            marker.map = mapView
          
            mapView.selectedMarker = marker //  the specific marker you want to remove or modify by set it as selectedMarker on the map.
          

          然后你想删除或修改

          mapView.selectedMarker.map = nil //example to remove the marker form the map.
          

          希望对您的情况有用。

          【讨论】:

            【解决方案7】:

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

            【讨论】:

            • 我认为这不是真的。 mapView.clear() 应该只与 UI 有关,它向 Maps API 发出额外请求是没有意义的。
            猜你喜欢
            • 2016-06-21
            • 1970-01-01
            • 1970-01-01
            • 2015-04-09
            • 2012-10-17
            • 2013-09-29
            • 2015-06-05
            • 1970-01-01
            • 2018-10-13
            相关资源
            最近更新 更多