Mary Mary - 3 days ago 5
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()))
.width(16)
.color(Color.parseColor("#1b9e77"))
.geodesic(true));
line.setZIndex(1000);
}


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

https://www.dropbox.com/s/6waic988mj90kdk/2014-10-22%2012.48.04.png?dl=0

Answer

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);
    polyLine.setPoints(location);
}

This will make it much smoother.

Comments