【问题标题】:How to remove a single mapbox android annotation?如何删除单个 mapbox android 注释?
【发布时间】:2022-12-22 21:38:16
【问题描述】:

我才开始学习 mapbox 地图,每次创建另一个注释时我都试图删除 mapbox 注释。

我的代码:

bitmapFromDrawableRes(
            this@PagePlanRouteMap,
            R.drawable.red_marker

        )?.let {

            val annotationApi = mapView?.annotations
            val pointAnnotationManager = annotationApi?.createPointAnnotationManager(mapView!!)


            val pointAnnotationOptions: PointAnnotationOptions = PointAnnotationOptions()

                .withPoint(Point.fromLngLat(lng, lat))
                .withIconImage(it)

            pointAnnotationManager?.create(pointAnnotationOptions)
        }

你能帮我实现注释的删除吗——

pointAnnotationManager?.deleteAll()

或者还有另一种更好的方法吗?谢谢。

【问题讨论】:

    标签: kotlin mapbox mapbox-android mapbox-marker


    【解决方案1】:

    您可以使用pointAnnotationManager 中的delete() 方法。 它有 2 个不同的参数可供您传递:PointAnnotation 对象或 PointAnnotation 列表。

    例如:

    val pointAnnotation = pointAnnotationManager?.create(pointAnnotationOptions)
    pointAnnotationManager?.delete(pointAnnotation)
    

    要么

    pointAnnotationManager?.delete(listOf(pointAnnotation))
    

    【讨论】:

    • 也值得评论,因为我自己很难找到它。每个注释都有自己的点注释管理器。我在本地存储我所有的点注释管理器,如果我需要删除多个注释,我只需遍历我的点注释管理器列表并在 foreach 循环中使用删除功能。
    【解决方案2】:

    pointAnnotationManager?.deleteAll() 不适合我。如果你想删除所有点你可以使用binding.mapView.annotations.cleanup()

    【讨论】:

      猜你喜欢
      • 2011-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-26
      • 2023-03-12
      • 2016-04-24
      • 1970-01-01
      相关资源
      最近更新 更多