google 标记正在更新,但未使用 Java 删除以前的标记(需要帮助)
google markers are updating but not removing previous markers (help needed) using Java
我怎样才能删除旧标记,但它仍然可以更新我在地图中的最新位置
@Override
public void onMapReady(GoogleMap googleMap) {
locationListener = new LocationListener() {
@Override
public void onLocationChanged(@NonNull Location location) {
latLng = new LatLng(location.getLatitude(), location.getLongitude());
googleMap.addMarker(new MarkerOptions().position(latLng).flat(true).title("My Position").icon(BitmapDescriptorFactory.fromResource(R.drawable.marker1)));
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
}
};
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
try {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME, MIN_DIST, locationListener);
}
catch (SecurityException e){
e.printStackTrace();
}
}[enter image description here][1]
尝试使用 googleMap.clear();在 googleMap.addMarker() 之前;也许对你有帮助
我怎样才能删除旧标记,但它仍然可以更新我在地图中的最新位置
@Override public void onMapReady(GoogleMap googleMap) {
locationListener = new LocationListener() {
@Override
public void onLocationChanged(@NonNull Location location) {
latLng = new LatLng(location.getLatitude(), location.getLongitude());
googleMap.addMarker(new MarkerOptions().position(latLng).flat(true).title("My Position").icon(BitmapDescriptorFactory.fromResource(R.drawable.marker1)));
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
}
};
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
try {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME, MIN_DIST, locationListener);
}
catch (SecurityException e){
e.printStackTrace();
}
}[enter image description here][1]
尝试使用 googleMap.clear();在 googleMap.addMarker() 之前;也许对你有帮助