Mary Mary - 3 months ago 28
Android Question

Google Map API making lines smoother when bending

I am using Google Map API to get lines on the map in my application. I am loading the nodes of the lines from a database using following code:

// Add polyline "walks voda"
List<WalkLine> dbwalknodes = dbclass.queryWalksFromDatabase(this); // list of latlng

for (int i = 0; i < dbwalknodes.size() - 1 ; i++) {
WalkLine source = dbwalknodes.get(i);
WalkLine destination = dbwalknodes.get(i+1);
Polyline line = mMap.addPolyline(new PolylineOptions()
.add(new LatLng(source.getLat(), source.getLon()),
new LatLng(destination.getLat(), destination.getLon()))

Do you have any idea how to create the lines smoother while it bends than on the picture bellow? Is it possible?


You should not create a polyline for each two points, it should be a connected polyline with mulitple points, something like this:

public void drawRoute(List<LatLng> location) {
    polylineOptions = new PolylineOptions().width(MAPS_PATH_WIDTH).color(routeColor).addAll(location);
    polyLine = map.addPolyline(destinationRoutePolyLineOptions);

This will make it much smoother.