google_directions_api 包为 Google Directions API 提供了 Flutter 接口,使开发者能够使用各种交通方式(如驾车、步行、骑行和公共交通)在位置之间计算路线。它支持多种平台,包括 Android、iOS、Web、macOS、Windows 和 Linux。该包简化了与 Google 路由服务的集成,使应用程序能够显示逐向导航、行程时间估算和距离计算。它非常适合需要路线数据的导航、行程规划和基于位置的应用程序。
适合场景
导航应用
行程规划功能
配送路线优化
基于位置的服务增强
实时交通方向查询
主要特点
支持多种传输模式
跨平台兼容性
简单的 API 集成
路线距离和时长计算
逐向导航指引支持
适合对象
开发导航工具的开发者
需要路线规划的应用
旅行和物流应用
移动和Web位置服务
集成 Google 地图路线规划功能
使用建议
需要 Google Cloud Platform API 密钥
根据使用情况应用速率限制
大量使用时可能会产生额外费用
实时数据需要互联网连接
需要正确处理API错误响应
原始 README
以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。
google_directions_api
The Directions API is a service that calculates directions between locations. You can search for directions for several modes of transportation, including transit, driving, walking, or cycling.
Getting Started
The Directions API is a service that calculates directions between locations using an HTTP request.
With the Directions API, you can:
Search for directions for several modes of transportation, including transit, driving, walking or cycling.
Return multi-part directions using a series of waypoints.
Specify origins, destinations, and waypoints as text strings (e.g. "Chicago, IL" or "Darwin, NT, Australia"), or as latitude/longitude coordinates, or as place IDs.
The API returns the most efficient routes when calculating directions. Travel time is the primary factor optimized, but the API may also take into account other factors such as distance, number of turns and many more when deciding which route is the most efficient.
Note: This service is not designed to respond in real time to user input.
For full info about Directions API visit official documentation
Usage
import'package:google_directions_api/google_directions_api.dart';
voidmain() {
DirectionsService.init('API_KEY');
final directionsService = DirectionsService();
final request = DirectionsRequest(
origin: 'New York',
destination: 'San Francisco',
travelMode: TravelMode.driving,
);
directionsService.route(request,
(DirectionsResult response, DirectionsStatus status) {
if (status == DirectionsStatus.ok) {
// do something with successful response
} else {
// do something with error response
}
});
}
Feature requests and Bug reports
Feel free to post a feature requests or report a bug here.