I am trying to move the marker according to the polyline and with animation. Similar to the below image:
Mapbox is already giving this kind of demo. But I w
The problem is the way you are creating your Location objects. You are using the Location (String provider) constructor that Construct a new Location with a named provider (documentation):
By default time, latitude and longitude are 0, and the location has no bearing, altitude, speed, accuracy or extras.
In your case you are not creating a Location with your desired coordinates but a Location whose provider's name is String.valueOf(directionPoint.get(i)) but the Location objects are created with latitude and longitude = 0.
The correct way to create the Location objects is as follows:
Location location = new Location(LocationManager.GPS_PROVIDER);
location.setLatitude(directionPoint.get(i).latitude);
location.setLongitude(directionPoint.get(i).longitude);
Location newlocation = new Location(LocationManager.GPS_PROVIDER);
newlocation.setLatitude(directionPoint.get(i+1).latitude);
newlocation.setLongitude(directionPoint.get(i+1).longitude);
Anyway take into account that you will get an ArrayIndexOutOfBoundsException because you are not taking into account that i+1 will be ==directionPoint.size() in the end.