Please I know if I use current location that time many answer I was seen. But My location come form service that is main problem. After service I will get all start point and end point. Now how can I animate this start point to end point? I already complete 0 index to 1 index moving with animation, but rest of this I did not. Now I need help to resolve this.
I have a location which I get from my service and I create route map in google maps. But Now I want to show a moving marker or a vehicle and animate it through start point to end point.
How can I implement an animation from start to the end point?This is my method and I show the route start point to end point with a polyline.
private void setMapMarker(GoogleMap googleMap) {
googleMap.clear();
MapsInitializer.initialize(Objects.requireNonNull(getActivity()).getApplicationContext());
api = ApiClient.getClient().create(ApiInterface.class);
LocationInfo locationInfo = new LocationInfo();
locationInfo.setMOV_DATE(fromDate.getText().toString());
locationInfo.setEMPLOYE_ID(employeeID);
locationInfo.setSTART_TIME(fromTime.getText().toString());
locationInfo.setEND_TIME(toTime.getText().toString());
Call<List<RouteList>> listCall = api.getLocation(locationInfo);
APIHelper.enqueueWithRetry(listCall, new Callback<List<RouteList>>() {
@Override
public void onResponse(Call<List<RouteList>> call, Response<List<RouteList>> response) {
try {
if (response.isSuccessful()) {
List<RouteList> list = response.body();
Map<String, List<RouteList>> map = getEmployeeList(list);
if (list == null || list.isEmpty() || list.equals(0)) {
googleMap.clear();
Toast.makeText(getActivity(), "No data found", Toast.LENGTH_SHORT).show();
} else {
for (Map.Entry<String, List<RouteList>> entry : map.entrySet()) {
String employee = entry.getKey();
List<RouteList> list1 = map.get(employee);
if (list1.size() > 0) {
List<LatLng> latlng = new ArrayList<>();
for (int i = 0; i < list1.size(); i++) {
double lat = Double.parseDouble(list1.get(i).getM_LATITUDE().trim());
double lng = Double.parseDouble(list1.get(i).getM_LONGITDE().trim());
String name = list1.get(i).getEMGIS_TIME();
latlng.add(new LatLng(lat, lng));
LatLng mLatlng = new LatLng(lat, lng);
if (googleMap != null) {
googleMap.addMarker(new MarkerOptions().position(mLatlng).title(name).snippet(""));
cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lng), 12.0f);
googleMap.animateCamera(cameraUpdate);
}
PolylineOptions rectOptions = new PolylineOptions().addAll(latlng);
rectOptions.color(generator.getRandomColor());
Objects.requireNonNull(googleMap).addPolyline(rectOptions);
}
} catch (Exception e) {
Toast.makeText(getActivity(), "Error:" + e, Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
@Override
public void onFailure(Call<List<RouteList>> call, Throwable t) {
call.cancel();
Toast.makeText(getActivity(), t.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
already show route map.