場所が変更されるとすぐに、現在の場所を中心にしてアンドロイドの Google マップ v2 に円を描こうとしています。今私が見ているのは、場所が変更されるたびに、前の円を削除せずに円が描かれ続けます(場所が同じ場合は互いに重なります)。マーカーでも同じことが起こっています。
以下は、Googleマップv2で円を描くために使用しているコードです
@Override
public void onLocationChanged(Location location) {
if (location != null) {
// Create a LatLng object for the current location
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
// Show the current location in Google Map
map.moveCamera(CameraUpdateFactory.newLatLng(latLng));
// Zoom in the Google Map
map.animateCamera(CameraUpdateFactory.zoomTo(14));
CircleOptions circleOptions = new CircleOptions().center(latLng) // set center
.radius(1000) // set radius in meters
.fillColor(Color.TRANSPARENT) // default
.strokeColor(0x10000000).strokeWidth(5);
myCircle = map.addCircle(circleOptions);
map.addMarker(new MarkerOptions().position(latLng).title("You are here!"));
}
次回円が描画されるたびに、以前の円とマーカーが Google マップからクリアされるようにするにはどうすればよいですか。コードにどのような変更を加える必要がありますか?
どんな助けでも大歓迎です。