3

場所が変更されるとすぐに、現在の場所を中心にしてアンドロイドの 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 マップからクリアされるようにするにはどうすればよいですか。コードにどのような変更を加える必要がありますか?

どんな助けでも大歓迎です。

4

3 に答える 3

1
map.clear();

if (location != null) の前にこれを追加

そのため、場所が変わるたびにすべてのマーカーと円が削除され、再度描画されます

于 2013-05-22T06:16:51.343 に答える
0

まず、円を描くのと同じように、マーカーへの参照を維持します

myMarker = map.addMarker(new MarkerOptions().position(latLng).title("You are here!"));

それらを削除したい場合は、次のように呼び出しますremove()

myCircle.remove();
myMarker.remove();
于 2013-05-22T07:17:56.310 に答える