So I'm making an app and I need continuous location updates to move my custom location marker. I wanted to have a smooth marker movement like Uber has. I implemented SmartLocation library using FusedLocationProvider, location accuracy is set to HIGH, and location is updated every second, yet for some reason I'm getting slow updates that are not accurate. Can someone tell me what I'm doing wrong?
public void onLocationUpdatedListenerInit(){
onLocationUpdatedListener=new OnLocationUpdatedListener() {
@Override
public void onLocationUpdated(Location location) {
animateMarker(location, myLocation);
}
};
}
public void startingLocationTracking(){
LocationParams.Builder builder = new LocationParams.Builder().setAccuracy(LocationAccuracy.HIGH)
.setDistance(0)
.setInterval(1000);
SmartLocation.with(this).location(new LocationGooglePlayServicesProvider()).continuous().config(builder.build()).start(onLocationUpdatedListener);
}
AnimateMarker method:
public static void animateMarker(final Location destination, final Marker marker) {
if (marker != null) {
final LatLng startPosition = marker.getPosition();
final LatLng endPosition = new LatLng(destination.getLatitude(), destination.getLongitude());
final float startRotation = marker.getRotation();
final LatLngInterpolator latLngInterpolator = new LatLngInterpolator.LinearFixed();
ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, 1);
valueAnimator.setDuration(1000); // duration 1 second
valueAnimator.setInterpolator(new LinearInterpolator());
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override public void onAnimationUpdate(ValueAnimator animation) {
try {
float v = animation.getAnimatedFraction();
LatLng newPosition = latLngInterpolator.interpolate(v, startPosition, endPosition);
marker.setPosition(newPosition);
marker.setRotation(computeRotation(v, startRotation, destination.getBearing()));
} catch (Exception ex) {
// I don't care atm..
}
}
});
valueAnimator.start();
}
}