I want to build my track using GPS on an Android device.
I have no problem displaying the completed route, but itβs hard for me to show the track when I move.
So far I have found two different ways to do this, but none of them are particularly satisfactory.
METHOD 1
PolylineOptions track = new PolylineOptions(); Polyline poly; while (moving) { Latlng coord = new LatLng(lat,lng); // from LocationListener track.add(coord); if (poly != null) { poly.remove(); } poly = map.addPolyline(track); }
those. create a polyline by deleting it before adding new coordinates, and then adding it back.
It is terribly slow.
METHOD 2
oldcoord = new LatLng(lat,lng);; while (moving) { PolylineOptions track = new PolylineOptions(); LatLng coord = new (LatLng(lat,lng); track.add(oldcoord); track.add(coord); map.addPolyline(track); oldcoord = coord; }
those. build a series of single polylines.
Despite the fact that this makes it much faster than method 1, it looks rather jagged, especially at lower zoom levels, because each polyline is square, and these are only the angles that actually touch.
Is there a better way, and if so, what is it?
source share