搜尋分類、套件與程式碼儲存庫

google_maps_routes 封面
套件詳情v1.1.2

google_maps_routes

一個透過使用 Google 地圖方向 API 在 Google 地圖上繪製路線的套件。

AndroidiOSWeb
近 30 天下載
850
喜歡數
29
Pub 分數
140

安裝套件

flutter pub add google_maps_routes

套件介紹

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

一個 Flutter 套件,可使用 Google Directions API 在 Google 地圖上繪製路線。它透過取得並呈現位置之間的導航路徑,簡化了路線視覺化,支援在 Android、iOS 和 Web 平台上實時導航路徑。此套件與 Google Maps for Flutter 無縫整合,讓開發者能夠顯示多段線路徑、途經點及旅行細節。非常適合需要逐向導航或基於位置的路線功能之應用程式。

適用情境

  • 顯示駕車導航
  • 可視化步行或騎行路線
  • 整合逐向導航
  • 建構交付或共乘應用
  • 建立旅行行程規劃工具

主要特色

  • 使用折線繪製路線
  • 支援多個途經點
  • 與 Google Directions API 集成
  • 跨平台相容性(Android、iOS、Web)
  • 輕鬆設定,設定最少

適合對象

  • 導航應用開發者
  • 物流與配送應用
  • 旅行和旅遊應用
  • 基於位置的服務平台
  • 需要動態路由渲染的應用

使用建議

  • 需要有效的 Google Maps API 金鑰
  • 依賴互聯網連接
  • 可能會產生來自 Google Directions API 的使用費用
  • 僅限 Google 地圖平台
  • 根據API使用層級應用速率限制

原始 README

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

google_maps_routes

This is a package for creating routes on google maps using the directions API from Google. Routes are drawn with help of the flutter_polyline_points package.

Screenshot

example-route

Usage

To use the google_maps_routes package, first depend on it.

Then import it where you want to use it

import 'package:google_maps_routes/google_maps_routes.dart';

To use it you need a List of points like this:

/// LatLng is included in google_maps_flutter
List<LatLng> points = [
    LatLng(latitude, longitude),
    LatLng(latitude, longitude),
    LatLng(latitude, longitude),
    LatLng(latitude, longitude),
];

Then you need to instantiate this plugin

MapsRoutes route = new MapsRoutes();

To create a route, just call the following function:

/// routeName is a string and can be anything; it can include spaces but
/// they will be replaced with a dash
/// example: 'Example route' turns into 'Example-route'

/// color is a Color type and will be used as the polyline color:
/// example: Color.fromRGBO(130, 78, 210, 1.0)

/// googleApyKey is a string and is a google directions API key
/// example: get it at
/// https://developers.google.com/maps/documentation/directions/get-api-key
await route.drawRoute(points, routeName, color, googleApiKey);

To use a different travel mode, use the travelMode parameter.

/// Options: driving, bicycling, transit, walking
await route.drawRoute(
    points,
    routeName,
    color,
    googleApiKey,
    travelMode: TravelModes.walking
);

To display the polylines you need to add a polylines parameter to your google map widget.

GoogleMap(polylines: route.routes),

If you ever want to clear the routes, just call:

route.routes.clear();

If you want to calculate the distance of the route use you call the following function with the same List of points you used for drawing the route. You can also use it by itself.

/// Initialize a calculator
DistanceCalculator distanceCalculator = new DistanceCalculator();

/// Call a function that returns a string
/// Pass it the List of points
/// By default it will return with 1 decimal point but you can pass an 
/// option that changes that 
distanceCalculator.calculateRouteDistance(points, decimals: 1);
Credits

所屬分類

依賴

依賴清單 2 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。