在点击android中的信息窗口时,从地图中删除标记和圆圈。可能吗?

时间:2013-11-18 21:50:54

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

我正在尝试删除地图上1个标记周围的圆圈。

我可以删除我的标记,但不知道如何删除相应中心的圆圈。

这是我的代码:

    mGoogleMap.setOnMapLongClickListener(new OnMapLongClickListener() {
            @Override
            public void onMapLongClick(LatLng point) {

            double dblLatitude=point.latitude;
                double dblLongitude=point.longitude;
                String strAddress=getAddress(dblLatitude, dblLongitude);
                drawMarker(point, strAddress);
                drawCircle(point);
            }
    });

mGoogleMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {


            @Override
            public void onInfoWindowClick(final Marker marker) {
                AlertDialog.Builder mAlertDialogBuilder = new AlertDialog.Builder(Map.this);
                mAlertDialogBuilder.setTitle(getString(R.string.delete_item_title));
                mAlertDialogBuilder.setMessage(marker.getSnippet());
                mAlertDialogBuilder.setPositiveButton(getString(R.string.delete_item_delete_button),
                        new DialogInterface.OnClickListener(){

                            @Override
                            public void onClick(DialogInterface dialog,int id) {

                                LatLng mLatLng = marker.getPosition(); //this is the center


                                marker.remove();
                              // here i also want to remove the circle


                            }
                        })
                .setNegativeButton(getString(R.string.delete_item_cancel_button), new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.dismiss();
                    }
                });

                AlertDialog ad = mAlertDialogBuilder.create();
                ad.show();


            }
        });

以下是我绘制圆圈和标记的方法:

    private void drawCircle(LatLng point){
    CircleOptions circleOptions = new CircleOptions();
    circleOptions.center(point);
    circleOptions.radius(500);
    circleOptions.strokeColor(Color.BLACK);
    circleOptions.fillColor(0x30ff0000);
    circleOptions.strokeWidth(2);

    mGoogleMap.addCircle(circleOptions);
}

private void drawMarker(LatLng point , String strPlace){
    MarkerOptions markerOptions = new MarkerOptions();
    markerOptions.position(point);
    markerOptions.title(strPlace);
    markerOptions.snippet(strPlace);
    Log.w(TAG, "Drawing at: " + strPlace);

    mGoogleMap.addMarker(markerOptions);

}

提前预订

1 个答案:

答案 0 :(得分:1)

创建时将每对保存在Map<Marker, Circle>中。注意:addMarker会返回Marker个对象。

在致电marker.remove()之前也

Circle circle = myMarkerCircleMap.remove(marker);
circle.remove();