google_maps_routes
This is a package for creating routes on google maps using the directions API from Google.
Routes are drawn with help of the flutter_polyline_points package.
Screenshot
Usage
To use the google_maps_routes package, first depend on it.
Then import it where you want to use it
import 'package:google_maps_routes/google_maps_routes.dart';
To use it you need a List of points like this:
List<LatLng> points = [
LatLng(latitude, longitude),
LatLng(latitude, longitude),
LatLng(latitude, longitude),
LatLng(latitude, longitude),
];
Then you need to instantiate this plugin
MapsRoutes route = new MapsRoutes();
To create a route, just call the following function:
await route.drawRoute(points, routeName, color, googleApiKey);
To use a different travel mode, use the travelMode parameter.
await route.drawRoute(
points,
routeName,
color,
googleApiKey,
travelMode: TravelModes.walking
);
To display the polylines you need to add a polylines parameter to your google map widget.
GoogleMap(polylines: route.routes),
If you ever want to clear the routes, just call:
route.routes.clear();
If you want to calculate the distance of the route use you call the following function with the same List of points you used for drawing the route. You can also use it by itself.
DistanceCalculator distanceCalculator = new DistanceCalculator();
distanceCalculator.calculateRouteDistance(points, decimals: 1);
Credits