open_route_service 0.5.1 open_route_service: ^0.5.1 copied to clipboard
An encapsulation made around OpenRouteService APIs, for Dart and Flutter projects, to easily generate Routes and their data.
open_route_service #
An encapsulation made around OpenRouteService API for Dart and Flutter projects. Made for the easy generation of Routes and Directions on Maps, Isochrones, Time-Distance Matrix, Pelias Geocoding, POIs, Elevation and routing Optimizations using their amazing API.
Features #
The goal is to develop an all-encompassing package that can encapsulate everything OpenRouteService API offers.
With all of their internal Optimizations, this includes:
-
Directions: Route Generation between any two or more coordinates for any mode of transportation. For example, from a starting point to a destination on
'foot-walking'
.This gives a
List
ofCoordinates
which can then be easily used to draw a Polyline route on a map in a Flutter Application or anything else you can think of.Route Drawn on Map using Coordinates -
Elevation: Get the elevation of a coordinate or a list of coordinates. Fetches the [ElevationData] by taking a 2D [coordinate] and enriching it with elevation from a variety of datasets. Uses the POST method for the endpoint.
Elevation Response Received -
Isochrones: Obtain Isochrone (areas of reachability) Data for the locations given. The isochrone is a polygon that encloses a given point and is bounded by a given time.
The isochrone data can be used to draw them on a map in a Flutter Application, or anything else you can think of.
Isochrone Drawn on Map -
Time-Distance Matrix:
-
Pelias Geocoding:
-
POIs:
Appropriate tests have also been written for each of the above APIs and can be used to check if the package and/or API are functioning properly.
Getting started #
Run dart pub add open_route_service
or flutter pub add open_route_service
to install the package.
Usage #
- Import the package:
import 'package:open_route_service/open_route_service.dart';
where needed. - Create a new instance of the class with your OpenRouteService API Key:
OpenRouteService openRouteService = OpenRouteService(apiKey: 'YOUR-API-KEY');
- Use the handy class methods to easily generate Directions, Isochrones, Time-Distance Matrix, Pelias Geocoding, POIs, Elevation and routing Optimizations etc, letting the package handle all the complex HTTP requests in the background for you.
Example of how to use the package to use OpenRoute Service's Directions API:
import 'package:open_route_service/open_route_service.dart';
Future<void> main() async {
// Initialize the OpenRouteService with your API key.
final OpenRouteService client = OpenRouteService(apiKey: 'YOUR-API-KEY');
// Example coordinates to test between
const double startLat = 37.4220698;
const double startLng = -122.0862784;
const double endLat = 37.4111466;
const double endLng = -122.0792365;
// Form Route between coordinates
final List<Coordinate> routeCoordinates = await client.getRouteDirections(
startCoordinate: Coordinate(startLat, startLng),
endCoordinate: Coordinate(endLat, endLng),
);
// Print the route coordinates
routeCoordinates.forEach(print);
// Map route coordinates to a list of LatLng (requires google_maps_flutter package)
// to be used in the Map route Polyline.
final List<LatLng> routePoints = routeCoordinates
.map((coordinate) => LatLng(coordinate.latitude, coordinate.longitude))
.toList();
// Create Polyline (requires Material UI for Color)
final Polyline routePolyline = Polyline(
polylineId: PolylineId('route'),
visible: true,
points: routePoints,
color: Colors.red,
width: 4,
);
// Use Polyline to draw route on map or do anything else with the data :)
}
Dependencies #
- Dart, for the Dart SDK which this obviously runs on.
- http, for making HTTP requests to the API endpoints.
Contribution Guidelines #
-
Contributions are welcome on GitHub. Please ensure all the tests are running before pushing your changes. Write your own tests too!
-
File any issues or feature requests here or help me resolve existing ones. :)
Additional information #
-
Please contribute to OpenRouteService API by donating to help keep the service free and accessible to everyone.
-
Go through the full documentation here: OpenRouteService API Documentation
-
Reach out to me directly @dhi13man on Twitter or GitHub if you have any general questions or suggestions.