How can i remove the old markers but still it can update my latest location in the map
@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]
Try use googleMap.clear(); before googleMap.addMarker(); maybe it help you