How to Draw Route in Google Maps API V2 from my location [duplicate]

Assuming you have at least 2 location objects you can draw a polyline.
This method draws a semi-transparent blue line on the map given a list
of locations. This code is taken from an application currently on the
Android Play store (Simply Walking).

private void drawPrimaryLinePath( ArrayList<Location> listLocsToDraw )
{
    if ( map == null )
    {
        return;
    }

    if ( listLocsToDraw.size() < 2 )
    {
        return;
    }

    PolylineOptions options = new PolylineOptions();

    options.color( Color.parseColor( "#CC0000FF" ) );
    options.width( 5 );
    options.visible( true );

    for ( Location locRecorded : listLocsToDraw )
    {
        options.add( new LatLng( locRecorded.getLatitude(),
                                 locRecorded.getLongitude() ) );
    }

    map.addPolyline( options );

}

Leave a Comment