I am trying to update user location using:
private void addLocationIndicator(GeoCoordinates geoCoordinates,
LocationIndicator.IndicatorStyle indicatorStyle, double orient) {
LocationIndicator locationIndicator = new LocationIndicator();
locationIndicator.setLocationIndicatorStyle(indicatorStyle);
// A LocationIndicator is intended to mark the user's current location,
// including a bearing direction.
// For testing purposes, we create a Location object. Usually, you may want to get this from
// a GPS sensor instead.
Location location = new Location.Builder()
.setCoordinates(geoCoordinates)
.setTimestamp(new Date())
.setBearingInDegrees(orient)
.build();
locationIndicator.updateLocation(location);
// A LocationIndicator listens to the lifecycle of the map view,
// therefore, for example, it will get destroyed when the map view gets destroyed.
mapView.addLifecycleListener(locationIndicator);
}
I have to remove the previous indicator whenever the location is updated. Is there any method to remove previous location indicators, as it is being stacked up upon the last indicators as the user updates its location?
This is happening because you are creating a new object of
LocationIndicatorevery-timeaddLocationIndicator()is called. You should move theLocationIndicator locationIndicatordeclaration to class level instead of method level and only create the object once next time when method is called check iflocationIndicatoris not null then do not create a new object.