【问题标题】:Android Google Maps - remove marker with iconAndroid Google Maps - 删除带有图标的标记
【发布时间】:2017-08-18 11:10:34
【问题描述】:

我想在长按时删除标记,并将其放置在另一个地方而不清除整个地图。

现在圆半径工作正常,但自定义图钉图标未删除。 不应使用使用 GoogleMap.clear() 方法 - 地图上还有一些我不想刷新的其他对象。 我也尝试过 setPosition 方法并得到了完全相同的结果。 如何删除这个图标?

标记声明:

marker = googleMap.addMarker(new MarkerOptions().position(marker.getPosition()).draggable(true).title("INFO")
                    .infoWindowAnchor(0.5f,0.5f).visible(false)
                    .icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.pin_icon))));


this.googleMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {
            @Override
            public void onMapLongClick(LatLng latLng) {
                if (marker != null) {
                    marker.remove();
                }

                createMarker(latLng);

            }
        });


private void createMarker(LatLng latLng) {
        marker = googleMap.addMarker(new MarkerOptions().position(latLng).draggable(true).title("INFO")
                .infoWindowAnchor(0.5f,0.5f)
                .icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.ic_pin_gr))));

    }

【问题讨论】:

  • 显示你添加这个标记的代码

标签: java android google-maps google-maps-api-3 marker


【解决方案1】:

我使用这种方法来创建标记,并且只需 setPosition(new Latlng(...)) 工作。

marker = mGoogleMap.addMarker(new MarkerOptions()
                    .anchor(0.5f, 0.5f)
                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_pin))
                    .position(new LatLng(cab.getLatitude(), cab.getLongitude())));

您是否尝试在 setPosition() 内的 onLongClick() 方法中替换 marker.remove();

【讨论】:

  • 你好 Michael,是的,我确实用 setPosition 替换了它,但图标仍然没有消失 :(
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-09-06
  • 2012-07-20
  • 2012-05-24
  • 2014-08-04
  • 2013-05-02
  • 1970-01-01
  • 2011-10-07
相关资源
最近更新 更多