【问题标题】:How to remove a particular shape from Google Maps in Android如何在 Android 中从 Google 地图中删除特定形状
【发布时间】:2014-01-26 16:00:39
【问题描述】:

我在 Android 的 Google 地图上创建了一些形状,然后单击按钮,我想删除一个特定的形状。

developer guide,我发现了这个:

公共无效删除()

从地图中移除多边形。

我使用了这个代码:

@Override
        public void onClick(View view)
        {
          if (shape != null)
          {
            shape.remove();
            Log.w("DEBUG", "Shape removed");
          }
        }

什么都没有发生,形状仍然存在。我还应该使用什么?

【问题讨论】:

  • 如果您多次点击该形状,该形状最终会消失吗?可能是该形状被多次添加到地图中。尝试删除标记时我遇到了同样的问题。只是一个想法,因为我遇到了类似的问题。
  • 是的,你是对的。我多次添加了形状。如果您将评论移至答案,我会接受。
  • 好的,很高兴你解决了。

标签: android google-maps-android-api-2


【解决方案1】:

如果您多次点击该形状,该形状最终会消失吗?可能是该形状被多次添加到地图中。尝试删除标记时我遇到了同样的问题。只是一个想法,因为我有类似的问题

【讨论】:

    【解决方案2】:

    我猜你已经看过这个网页了,但以防万一,我建议你看看这个页面:https://developers.google.com/maps/documentation/android/shapes

    您必须创建以下类型的对象:PolylinePolygonCircle,然后,您可以将它们添加到地图的实例中。

    // Instantiates a new Polyline object and adds points to define a rectangle
    PolylineOptions rectOptions = new PolylineOptions()
        .add(new LatLng(37.35, -122.0))
        .add(new LatLng(37.45, -122.0))  // North of the previous point, but at the same longitude
        .add(new LatLng(37.45, -122.2))  // Same latitude, and 30km to the west
        .add(new LatLng(37.35, -122.2))  // Same longitude, and 16km to the south
        .add(new LatLng(37.35, -122.0)); // Closes the polyline.
    
    // Get back the mutable Polyline
    Polyline polyline = myMap.addPolyline(rectOptions);
    

    之后,您可以使用myMap.clear()myMap 对象中删除元素。

    希望对您有所帮助。

    【讨论】:

    • 你的建议的问题是它清除了整个地图,所以我的其他形状也消失了。所以我需要使用remove功能。
    【解决方案3】:

    Polygon 有一个方法 remove() 从地图中删除多边形

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-06
      • 2017-08-15
      • 2017-07-07
      • 2012-07-30
      • 1970-01-01
      • 2023-02-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多