删除google_maps_flutter中的标记 [英] Remove marker in google_maps_flutter

查看:142
本文介绍了删除google_maps_flutter中的标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了 Google Maps for Flutter 我知道如何添加标记,因为示例中明确给出了标记

I have added Google Maps for Flutter i know how to add a marker as it is given clearly in there examples

MarkerOptions _options = new MarkerOptions(
          position: LatLng(
            driver_lat,
            driver_lng,
          ),
          infoWindowText:
              const InfoWindowText('An interesting location', '*'));

      Marker marker = new Marker('1', _options);

      //Adding Marker
      googleMapController.addMarker(_options);

我正在删除以下标记

googleMapController.removeMarker(marker);

要添加标记,它将MarkerOptions对象作为参数,但是要删除标记,它要求将Marker对象作为参数,而我删除的标记代码不起作用. 我收到以下错误

for adding the marker it is taking MarkerOptions object as a parameter but for removing the marker it is asking for Marker object as parameter and my removing marker code is not working. i am getting the below error

Failed assertion: line 201 pos 12: '_markers[marker._id] == marker': is not true.

推荐答案

有两种方法,一种是通过clearMarkers()方法

There are two ways to do this, one is via clearMarkers() Method

mapController.clearMarkers();

另一种是通过定位mapController.markers

mapController.markers.forEach((marker){
      mapController.removeMarker(marker);
});

这篇关于删除google_maps_flutter中的标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆