Each and everytime when you get new Latitude and Longitude, just call one user defined method, like, drawTrack()
. But before that whatever value you got first time, just store that value in like in previous_lat
and previous_long
variable. Then, when you got lat-long second time that means your source lat-long is previous_lat
and previous_long
and latest one is which you have got currently. Then give that 4 vaues to drawTrack()
method.
Inside DrawTrack()
method,
googleMap.addPolyline(new PolylineOptions().add(new LatLng(Double.parseDouble(YOUR PREVIOUS LATITUDE VALUE), Double.parseDouble(YOUR PREVIOUS LONGITUDE VALUE), new LatLng(Double.parseDouble(YOUR LATEST LATITUDE VALUE), Double.parseDouble(YOUR LATEST LONGITUDE VALUE).width(5) .color(getResources().getColor(R.color.BLACK)).geodesic(true));