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

套件詳情v3.0.2

gmaps_by_road_distance_calculator

這是一個用於計算地圖上兩點之間道路距離的套件。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
135
喜歡數
14
Pub 分數
120

安裝套件

flutter pub add gmaps_by_road_distance_calculator

套件介紹

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

此 Flutter 套件使用 Google 地圖資料計算兩個地理點之間的路徑距離。它透過利用實際道路網絡,實現精確的旅行距離與路線預估,非常適合導航與物流應用。該套件支援多種平台,包含 Android、iOS、Web、macOS、Windows 與 Linux,確保廣泛相容性。開發者可透過簡單的指令列新增輕鬆整合。專為需要根據實際道路路徑而非直線(如飛鳥般)測量之精確即時距離計算用途而設計。

適用情境

  • 導航應用
  • 物流與配送追蹤
  • 路線規劃工具
  • 行程時間估計
  • 基於距離的地圖篩選

主要特色

  • 道路距離計算
  • 多平台支援
  • Google 地圖整合
  • 簡單 API 界面
  • 即時距離更新

適合對象

  • 開發導航功能的開發者
  • 需要精確旅行距離的應用程式
  • 跨平台地圖應用
  • 配送與拼車服務
  • 位置感知分析

使用建議

  • 需要網路連接以進行API呼叫
  • 依賴於 Google 地圖後端的可用性
  • 高請求量可能產生使用費用
  • 僅限谷歌地圖提供的道路網絡資料

原始 README

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

gmaps_by_road_distance_calculator

A Dart package for calculating distances along roads and routes using multiple APIs and formats.

Features

  • Calculate distances between geographical points
  • Support for real-time distance tracking
  • Calculate distances along roads using OSRM (Open Source Routing Machine)
  • Multiple travel modes: driving, bicycling, walking, transit
  • Parse and work with GPX and KML route files
  • Decode polyline strings to geographical points

Getting Started

Installation

Add the package to your pubspec.yaml:

dependencies:
  gmaps_by_road_distance_calculator: ^1.0.0

Then run:

flutter pub get
Import
import 'package:gmaps_by_road_distance_calculator/gmaps_by_road_distance_calculator.dart';

Usage

Basic Distance Calculation

Calculate straight-line distances between geographical points:

final calculator = ByRoadDistanceCalculator();
final points = [
  LatLng(37.7749, -122.4194), // San Francisco
  LatLng(34.0522, -118.2437), // Los Angeles
];

// Calculate straight-line distance in kilometers
final distance = calculator.calculateDistance(points);
print('Distance: $distance km');
Calculate Road Distance Using OSRM

Calculate actual road distance between two points using the OSRM service:

final calculator = ByRoadDistanceCalculator();
final start = LatLng(37.7749, -122.4194); // San Francisco
final end = LatLng(34.0522, -118.2437); // Los Angeles

// Calculate driving distance
calculator.calculateDistanceViaOSRM(
  start: start,
  end: end,
  mode: TravelModes.driving,
).then((result) {
  print('Driving distance: ${result.distance} km');
  print('Route consists of ${result.points.length} points');
});

// Calculate walking distance
calculator.calculateDistanceViaOSRM(
  start: start,
  end: end,
  mode: TravelModes.walking,
).then((result) {
  print('Walking distance: ${result.distance} km');
});
Real-time Distance Tracking

Track and update distance in real-time as new points are added:

final calculator = ByRoadDistanceCalculator();

// Listen for distance updates
calculator.distanceUpdates.listen((distance) {
  print('Current distance: $distance km');
});

// Add points as they become available (e.g., from GPS)
calculator.addPoint(LatLng(37.7749, -122.4194));
calculator.addPoint(LatLng(37.7850, -122.4100));
calculator.addPoint(LatLng(37.7950, -122.4000));

// Reset tracking when needed
calculator.clearPoints();
Working with GPX Files

Parse GPX files to extract geographical points:

final calculator = ByRoadDistanceCalculator();
final gpxContent = '''
<?xml version="1.0" encoding="UTF-8"?>
<gpx version="1.1">
  <trk>
    <trkseg>
      <trkpt lat="37.7749" lon="-122.4194"></trkpt>
      <trkpt lat="37.7850" lon="-122.4100"></trkpt>
      <trkpt lat="37.7950" lon="-122.4000"></trkpt>
    </trkseg>
  </trk>
</gpx>
''';

final points = calculator.parseGPX(gpxContent);
final distance = calculator.calculateDistance(points);
print('Distance from GPX: $distance km');
Working with KML Files

Parse KML files to extract geographical points:

final calculator = ByRoadDistanceCalculator();
final kmlContent = '''
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
    <Placemark>
      <LineString>
        <coordinates>
          -122.4194,37.7749,0
          -122.4100,37.7850,0
          -122.4000,37.7950,0
        </coordinates>
      </LineString>
    </Placemark>
  </Document>
</kml>
''';

final points = calculator.parseKML(kmlContent);
final distance = calculator.calculateDistance(points);
print('Distance from KML: $distance km');
Decode Polyline Strings

Convert encoded polyline strings to geographical points:

final encodedPolyline = "_p~iF~ps|U_ulLnnqC_mqNvxq`@";
final points = ByRoadDistanceCalculator.decodePolylineString(encodedPolyline);

Advanced Configuration

Custom OSRM Server

You can specify a custom OSRM server URL if you're hosting your own instance:

calculator.calculateDistanceViaOSRM(
  start: start,
  end: end,
  mode: TravelModes.driving,
  customOSRMUrl: 'https://your-custom-osrm-server.com/route/v1',
).then((result) {
  print('Distance: ${result.distance} km');
});

Dependencies

This package depends on:

  • latlong2: For geographical coordinate operations
  • http: For API requests
  • xml: For parsing GPX and KML files

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Issues and Feedback

Please file issues and feedback here.

所屬分類

依賴

依賴清單 4 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。