Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 574
Mary Avatar asked Jun 22 '26 00:06

Mary


1 Answers

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.

like image 85
Squeazer Avatar answered Jun 23 '26 15:06

Squeazer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!