Calculate Route
This example demonstrates how to create a Flutter app that calculates a route between two locations and displays it on a map using Maps SDK for Flutter.
How It Works
The example app demonstrates the following features:
- Calculate a route between two landmarks.
- Display the route on a map and allow user interaction with the route.
- Provide options to cancel route calculation or clear the routes from the map.
UI and Map Integration
This code sets up the basic structure of the app, including the map and the app bar. It also provides buttons in the app bar for building, canceling, and clearing routes.
Route Calculation and Map Interaction
This code handles the calculation of routes between two landmarks, displays the routes on the map, and provides options to cancel or clear the routes. The map is centered on the calculated routes, and a label showing the distance and duration is displayed.
Route Selection
This code enables the user to select a specific route on the map by tapping on it. The selected route becomes the main route displayed.
Displaying Route Information
This code defines an extension on the Route class that calculates and formats the distance and duration of the route for display on the map.