open_route_service 1.1.0 icon indicating copy to clipboard operation
open_route_service: ^1.1.0 copied to clipboard

An encapsulation made around openrouteservice APIs, for Dart and Flutter projects, to easily generate Routes and their data.

example/open_route_service_example.dart

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<ORSCoordinate> routeCoordinates =
      await client.directionsRouteCoordsGet(
    startCoordinate: ORSCoordinate(latitude: startLat, longitude: startLng),
    endCoordinate: ORSCoordinate(latitude: endLat, longitude: endLng),
  );

  // Print the route coordinates
  routeCoordinates.forEach(print);

  // Map route coordinates to a list of LatLng (requires google_maps_flutter)
  // to be used in 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 :)
}
27
likes
130
pub points
72%
popularity

An encapsulation made around openrouteservice APIs, for Dart and Flutter projects, to easily generate Routes and their data.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

http

More

Packages that depend on open_route_service