How to draw interactive Polyline on route google maps v2 android
Instead of creating too many short Polyline
s just create one like here:
PolylineOptions options = new PolylineOptions().width(5).color(Color.BLUE).geodesic(true);
for (int z = 0; z < list.size(); z++) {
LatLng point = list.get(z);
options.add(point);
}
line = myMap.addPolyline(options);
I'm also not sure you should use geodesic
when your points are so close to each other.
I've created a couple of map tutorials that will cover what you need
Animating the map describes howto create polylines based on a set of LatLngs. Using Google APIs on your map : Directions and Places describes howto use the Directions API and animate a marker along the path.
Take a look at these 2 tutorials and the Github project containing the sample app.
It contains some tips to make your code cleaner and more efficient:
- Using Google HTTP Library for more efficient API access and easy JSON handling.
- Using google-map-utils library for maps-related functions (like decoding the polylines)
- Animating markers