搜尋套件、儲存庫與 APP 分類

open_route_service 封面
套件詳情v1.2.9

open_route_service

一個圍繞 openrouteservice API 的封裝,適用於 Dart 和 Flutter 專案,可輕鬆產生路線及其資料。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
1310
喜歡數
90
Pub 分數
150

安裝套件

flutter pub add open_route_service

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

open_route_service 套件為 Dart 與 Flutter 提供了 OpenRouteService API 的友善封裝,讓開發者能輕鬆將路線規劃與地理空間資料整合至應用程式中。它透過乾淨直覺的方法簡化計算路線、取得導航指示及存取地圖相關資訊等任務。適合需要逐步導航或旅行距離計算的位置類應用,支援多種平台,包括行動裝置、網頁與桌面。此套件輕量且文件完整,對初學者與資深開發者皆易於使用。

適用情境

  • 旅行應用中的路線規劃
  • 帶逐向指引的導航
  • 距離和時長計算
  • 基於地圖的物流追蹤
  • 地理空間資料檢索
  • 多平台位置服務

主要特色

  • 簡單 API 結合
  • 對多個平台的支援
  • 即時路線產生
  • JSON 回應解析
  • 內建錯誤處理
  • 跨平台相容性

適合對象

  • Flutter 開發人員建構導航功能
  • 需要路線優化的手機應用程式
  • 使用 OpenRouteService API 的項目
  • 尋求輕量級地理定位工具的開發者
  • 跨平台移動和網頁應用

使用建議

  • 需要來自 OpenRouteService 的 API 金鑰
  • 依賴互聯網連接
  • 受限於 OpenRouteService 的可用端點
  • 可能需要額外的解析來處理複雜回應
  • 根據訂閱層級應用速率限制

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

open_route_service

Build, Format, Test open_route_service version pub points OpenSSF Scorecard License: MIT

A Dart and Flutter client for openrouteservice directions, isochrones, matrices, geocoding, points of interest, elevation, and route optimization.

The package provides typed request and response models around the openrouteservice API for Dart and Flutter projects.

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.directionsRouteCoordsGet gives a List of ORSCoordinate 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 Flutter App Map using Coordinates
    Route Drawn on Map (Flutter)
  2. Elevation: Get the elevation of a coordinate, or a list of coordinates. Fetches the ElevationData by taking a 2D ORSCoordinate 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: Resolve input coordinates to addresses and vice versa. Provides functionality for geocoding autocomplete queries, search queries, and reverse geocoding.

    Reverse Geocoding Information used on Map
    Reverse Geocode on Map
  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.

Prerequisites

Installation

Run dart pub add open_route_service or flutter pub add open_route_service in your Dart/Flutter project directory to install the package.

After adding the package, AI coding agents can load its usage skill with dart run skills@ get.

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<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 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 :)
}

Security

Report vulnerabilities privately by following SECURITY.md. Do not include API keys or other credentials in issues, examples, or pull requests.

Contribution Guidelines

See CONTRIBUTING.md for the development workflow and test requirements. Use GitHub issues for reproducible bugs and focused feature requests.

Dependencies

  • Dart or Flutter, 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!

License

This package is available under the MIT License.

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。