An encapsulation made around openrouteservice API for Dart and Flutter projects.

Overview

open_route_service

License Language Language Contributors GitHub forks GitHub Repo stars Last Commit Build, Format, Test open_route_service version

This package is an encapsulation/wrapper made around openrouteservice API for Dart and Flutter projects.

The package enables the easy integration of the openrouteservice API with relevant data models, for generation of Routes and Directions on Maps, Isochrones, Time-Distance Matrix, Pelias Geocoding, POIs, Elevation, routing Optimizations etc, using their amazing API.

Contribute to openrouteservice API by donating to help keep the service free and accessible to everyone. For more information about the API, view the openrouteservice API documentation.

Contents

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:

  1. 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'.

    E.g. ORSDirections.getRouteCoordinates gives a List of Coordinates 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
    Route Drawn on Map
  2. Elevation: Get the elevation of a coordinate, or a list of coordinates. Fetches the ElevationData by taking a 2D coordinate or planar line geometry, and enriching it with elevation from a variety of datasets.

    Elevation Response Received
    Sample Elevation Response
  3. 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
    Isochrone Drawn on Map
  4. Time-Distance Matrix: Obtain one-to-many, many-to-one and many-to-many matrices for time and distance. Returns duration or distance matrix for multiple source and destination points.

  5. Pelias Geocoding:

  6. POIs: Obtains information about the Points of Interest (POIs) in the area surrounding a geometry which can either be a bounding box, polygon or buffered linestring, or point.

    The Points of Interest can be marked on a map in a Flutter Application, or their properties and information visualized in various ways, or anything else you can think of.

    Points of Interest Drawn on Map
    POI Drawn on Map
  7. Routing Optimizations: The optimization endpoint solves Vehicle Routing Problems and can be used to schedule multiple vehicles and jobs, respecting time windows, capacities and required skills.

    This service is based on the excellent Vroom project. Please also consult its API documentation.

    Optimization Data for Vroom Jobs and Vehicles extracted and their route information printed in Console
    Optimization Route Data

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 in your Dart/Flutter project directory to install the package.

Steps for Usage

  1. Import the package where needed:

    import 'package:open_route_service/open_route_service.dart';
  2. Create a new instance of the class with your openrouteservice API Key:

    OpenRouteService openrouteservice = OpenRouteService(apiKey: 'YOUR-API-KEY');
  3. 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 Usage

To use the package with the Directions API to generate and draw a Route on a map in a Flutter application:

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.getRouteCoordinates(
    startCoordinate: Coordinate(latitude: startLat, longitude: startLng),
    endCoordinate: Coordinate(latitude: endLat, longitude: 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 :)
}

Contribution Guidelines

Dependencies

  • Dart, for the Dart SDK which this obviously runs on.
  • http, for internally making RESTful HTTP Network requests to the API endpoints.

Additional information

Sponsor Message

The first release of this package was sponsored by Cashtic, a Cross-Platform peer-to-peer ATM cash network for Android and Web. Get it on Google Play!

Comments
  • Error when running matrixPost  with metrics: ['distance']

    Error when running matrixPost with metrics: ['distance']

    Hello. I'm getting the following error when doing a matrixPost with metrics different from the default ['duration'] TimeDistanceMatrix distanceMatrix = await client.matrixPost(locations: cities, metrics: ['distance'], units: 'm'); Do you have any idea why this happens? The request works OK in Postman, why is this happening in Flutter Dart? How can I fix it?

    Error: OpenRouteServiceException: Expected a value of type 'List<dynamic>', but got one of type 'Null'; Matrix value can't be determined for given inputs, as per https://openrouteservice.org/dev/#/api-docs/v2/matrix/{profile}/post, at url https://api.openrouteservice.org/v2/matrix/driving-car at Object.throw_ [as throw] (http://localhost:3277/dart_sdk.js:5080:11) at ORSMatrix$124matrixPost (http://localhost:3277/packages/open_route_service/src/open_route_service_base.dart.lib.js:1087:21) at ORSMatrix$124matrixPost.next (<anonymous>) at http://localhost:3277/dart_sdk.js:40641:33 at _RootZone.runUnary (http://localhost:3277/dart_sdk.js:40511:59) at _FutureListener.thenAwait.handleValue (http://localhost:3277/dart_sdk.js:35438:29) at handleValueCallback (http://localhost:3277/dart_sdk.js:35999:49) at _Future._propagateToListeners (http://localhost:3277/dart_sdk.js:36037:17) at [_completeWithValue] (http://localhost:3277/dart_sdk.js:35872:23) at async._AsyncCallbackEntry.new.callback (http://localhost:3277/dart_sdk.js:35906:35) at Object._microtaskLoop (http://localhost:3277/dart_sdk.js:40778:13) at _startMicrotaskLoop (http://localhost:3277/dart_sdk.js:40784:13) at http://localhost:3277/dart_sdk.js:36261:9

    opened by ghost 6
  • Add project setup to README.md

    Add project setup to README.md

    Apart from the usage instruction, there is currently nothing on how to setup the project and run the files in development mode.

    This would be helpful for contributions.

    opened by TheGreatRefrigerator 2
  • TODO: Integrate OpenRoute Service Optimization API with relevant Data Models and Tests.

    TODO: Integrate OpenRoute Service Optimization API with relevant Data Models and Tests.

    Optimization API

    API Documentation: https://openrouteservice.org/dev/#/api-docs/optimization

    The project structure is already set so just gotta fill in the dart files in the right places. :)

    help wanted 
    opened by Dhi13man 2
  • duplicate data issues

    duplicate data issues

    route optimizationDataPost isues showing duplicate data herer is project link https://github.com/sudoadarsh/travelling-salesman-flutter/blob/master/lib/main.dart

    opened by Vedp1998 1
  • Use api key from env variable

    Use api key from env variable

    One option to use your api key for tests without exposing it is implementing it as an environment variable and read it from there. Here is an example with github workflows: https://dev.to/jonathangomz/github-actions-for-dart-package-with-environment-variables-5heb

    opened by TheGreatRefrigerator 1
  • Repo cleanup

    Repo cleanup

    Little typo, wording and indentation fixing. The only real code change would be the cgiar attribution.

    Was there a reason for the .vscode in the repo?

    opened by TheGreatRefrigerator 1
  • TODO: Integrate OpenRoute Service GeoCode API with relevant Data Models and Tests.

    TODO: Integrate OpenRoute Service GeoCode API with relevant Data Models and Tests.

    GeoCode API

    API Documentation: https://openrouteservice.org/dev/#/api-docs/geocode

    The project structure is already set so just gotta fill in the dart files in the right places. :)

    help wanted Hacktoberfest 
    opened by Dhi13man 1
  • TODO: Integrate OpenRoute Service Pois API with relevant Data Models and Tests.

    TODO: Integrate OpenRoute Service Pois API with relevant Data Models and Tests.

    Pois API

    API Documentation: https://openrouteservice.org/dev/#/api-docs/pois

    The project structure is already set so just gotta fill in the dart files in the right places. :)

    help wanted 
    opened by Dhi13man 0
  • TODO: Integrate OpenRoute Service Matrix API with relevant Data Models and Tests.

    TODO: Integrate OpenRoute Service Matrix API with relevant Data Models and Tests.

    Matrix API

    API Documentation: https://openrouteservice.org/dev/#/api-docs/v2/matrix/{profile}/post

    The project structure is already set so just gotta fill in the dart files in the right places. :)

    opened by Dhi13man 0
  • TODO: Make Metadata schema class and include it into every data model it's needed in.

    TODO: Make Metadata schema class and include it into every data model it's needed in.

    Example metadata

    {
        "metadata": {
            "attribution": "openrouteservice.org | OpenStreetMap contributors",
            "service": "matrix",
            "timestamp": 1632652598861,
            "query": {
                "locations": [
                    [
                        9.70093,
                        48.477473
                    ],
                    [
                        9.207916,
                        49.153868
                    ],
                    [
                        37.573242,
                        55.801281
                    ],
                    [
                        115.663757,
                        38.106467
                    ]
                ],
                "profile": "driving-car",
                "responseType": "json"
            },
            "engine": {
                "version": "6.6.1",
                "build_date": "2021-07-05T10:57:48Z",
                "graph_date": "2021-09-12T10:05:32Z"
            }
        }
    }
    
    help wanted good first issue low-priority Hacktoberfest 
    opened by Dhi13man 2
Releases(v1.0.0)
  • v1.0.0(Oct 30, 2021)

    open_route_service v1.0.0

    License Language Language Contributors GitHub forks GitHub Repo stars Last Commit Build, Format, Test open_route_service version

    "Buy Me A Coffee"

    This package is an encapsulation/wrapper made around openrouteservice API for Dart and Flutter projects.

    The package enables the easy integration of the openrouteservice API with relevant data models, for the generation of Routes and Directions on Maps, Isochrones, Time-Distance Matrix, Pelias Geocoding, POIs, Elevation, routing Optimizations, etc, using their amazing API.

    This is the first stable release and includes the integration of:

    1. Directions (✅)
    2. Elevation (✅)
    3. Isochrones (✅)
    4. Time-Distance Matrix (✅)
    5. Pelias Geocoding (✅)
    6. Points of Interest (POIs) (✅)
    7. Routing Optimizations (✅), etc.

    Release on pub.dev: https://pub.dev/packages/open_route_service

    Source code(tar.gz)
    Source code(zip)
Owner
Dhiman Seal
Showing skills off.
Dhiman Seal
A mobile map based application to help people everywhere around the world get help

Wonder This is a mobile application made by flutter. The application is called "Wonder" because it will help people everywhere around the world to get

Sara Nersisian 1 Dec 2, 2021
A simple flexible API wrapper for coinbase commerce API. Totally unofficial.

coinbase_commerce A dart library that connects to interact with the Coinbase Commerce API. Enables projects to connect seamlessly to coinbase and rece

Onuoha Obinna 3 Oct 17, 2021
A Dart build script that downloads the Protobuf compiler and Dart plugin to streamline .proto to .dart compilation.

A Dart build script that downloads the Protobuf compiler and Dart plugin to streamline .proto to .dart compilation.

Julien Scholz 10 Oct 26, 2022
Minimal Dart wrapper to interact with Some Random Api. Easy to use, simplified and lightweight.

SRA - Some Random Api Minimal Dart wrapper to interact with Some Random Api. Easy to use, simplified and lightweight. Getting started Add the package

Yakiyo 3 Jan 4, 2023
Provides API to generate Dart source code

DartWriter DartWriter provides API to generate Dart source code. It can make your job easier while developing flutter/dart tools. You can also generat

Ahmet ÇELİK 11 Oct 24, 2022
Call OpenGL ES Api By Dart

Flutter GL Flutter GL can call OpenGL ES API with Dart Support iOS,Android,Web OpenGL ES API Now the api is similar to WebGL How to use Now this is on

zhaolei 163 Jan 5, 2023
This package binds to Cronet's native API to expose them in Dart.

Experimental Cronet Dart bindings This package binds to Cronet's native API to expose them in Dart. This is an HTTP Client Package with almost the sam

Google 103 Dec 9, 2022
A CLI tool to help generate dart classes from json returned from API

Json 2 Dart Command line utility Important note There is already a package called json2dart so this package will be called json2dartc ! This project w

Adib Mohsin 38 Oct 5, 2022
Volt is a wrapper over the Revolt API for easily writing bots using the Dart language.

Volt is a wrapper over the Revolt API for easily writing bots using the Dart language. It is currently in active development so not all of the functionality has yet been implemented.

null 8 Dec 13, 2022
This is a dart library covering nearly 100% of the latest Planning Center public API.

Planning Center API for Dart Planning Center is an online platform for church management. It provides multiple apps for things like check-ins, service

null 1 Oct 6, 2022
Cache json map to local file with Dart:io. Read file with sync api.

local_cache_sync 一个非常简单易用的Flutter本地储存库,适用于在本地储存一列轻量数据(例如用户保存在本地的设备信息,或者缓存一系列用户信息)。 local_cache_sync的所有方法都是同步,而不是异步的。这意味着你不需要使用await就可以获取数据。在flutter中,这

null 16 Jun 24, 2022
Converts SVG icons to OTF font and generates Flutter-compatible class. Provides an API and a CLI tool.

Fontify The Fontify package provides an easy way to convert SVG icons to OpenType font and generate Flutter-compatible class that contains identifiers

Igor Kharakhordin 88 Oct 28, 2022
Quiver is a set of utility libraries for Dart that makes using many Dart libraries easier and more convenient, or adds additional functionality.

Quiver is a set of utility libraries for Dart that makes using many Dart libraries easier and more convenient, or adds additional functionality.

Google 905 Jan 2, 2023
WhatsApp API package for flutter, to send message and product information.

WhatsApp API package for flutter, to send message and product information. Platform Support Android iOS MacOS Web Linux Windows ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ What

Rohit Chouhan 7 Nov 11, 2022
Dart wrapper via dart:ffi for https://github.com/libusb/libusb

libusb Dart wrapper via dart:ffi for https://github.com/libusb/libusb Environment Windows(10) macOS Linux(Ubuntu 18.04 LTS) Usage Checkout example Fea

Woodemi Co., Ltd 28 Dec 20, 2022
Extensible Dart interpreter for Dart with full interop

dart_eval is an extensible interpreter for the Dart language, written in Dart. It's powered under the hood by the Dart analyzer, so it achieves 100% c

Ethan 169 Dec 28, 2022
A Flutter library to make Rest API clients more easily. Inspired by Java Feing.

A Flutter library to make Rest API clients more easily. Inspired by Java Feing. Features Facilitated JSON encode and decode using common interfaces. F

null 2 Mar 15, 2022
JSON API parser for Flutter

Flutter Japx - JSON:API Decoder/Encoder Lightweight [JSON:API][1] parser that flattens complex [JSON:API][1] structure and turns it into simple JSON a

Infinum 23 Dec 20, 2022
This library contains methods that make it easy to consume Mpesa Api.

This library contains methods that make it easy to consume Mpesa Api. It's multi-platform, and supports CLI, server, mobile, desktop, and the browser.

Eddie Genius 3 Dec 15, 2021