├── .github
├── ISSUE_TEMPLATE
│ ├── bug_report.md
│ └── feature_request.md
├── PULL_REQUEST_TEMPLATE.md
└── workflows
│ └── dart_build.yml
├── .gitignore
├── AUTHORS
├── CHANGELOG.md
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── analysis_options.yaml
├── example
├── .gitignore
├── README.md
├── bin
│ └── main.dart
└── pubspec.yaml
├── lib
├── google_directions_api.dart
└── src
│ ├── directions.dart
│ ├── directions.request.dart
│ └── directions.response.dart
├── publish_commands.txt
├── pubspec.yaml
└── test
└── google_directions_api_test.dart
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: I have a problem with my Flutter application.
3 | about: You are writing an application with Flutter but the application is crashing
4 | or throws an exception, a widget is buggy, or something looks wrong.
5 | title: ''
6 | labels: ''
7 | assignees: ''
8 |
9 | ---
10 |
11 |
23 |
24 | ## Steps to Reproduce
25 |
26 |
27 |
28 | 1. Run `flutter create bug`.
29 | 2. Update the files as follows: ...
30 | 3. ...
31 |
32 | **Expected results:**
33 |
34 | **Actual results:**
35 |
36 |
37 | Logs
38 |
39 |
45 |
46 | ```
47 | ```
48 |
49 |
53 |
54 | ```
55 | ```
56 |
57 |
58 |
59 | ```
60 | ```
61 |
62 |
63 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest a new idea for Flutter.
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 |
22 |
23 | ## Use case
24 |
25 |
35 |
36 | ## Proposal
37 |
38 |
47 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ## Description
2 |
3 | *Replace this paragraph with a description of what this PR is doing. If you're modifying existing behavior, describe the existing behavior, how this PR is changing it, and what motivated the change. If you're changing visual properties, consider including before/after screenshots (and runnable code snippets to reproduce them).*
4 |
5 | ## Related Issues
6 |
7 | *Replace this paragraph with a list of issues related to this PR from our issue database. Indicate, which of these issues are resolved or fixed by this PR. There should be at least one issue listed here.*
8 |
9 | ## Tests
10 |
11 | I added the following tests:
12 |
13 | *Replace this with a list of the tests that you added as part of this PR. A change in behaviour with no test covering it
14 | will likely get reverted accidentally sooner or later. PRs must include tests for all changed/updated/fixed behaviors. See [Test Coverage].*
15 |
16 | ## Checklist
17 |
18 | Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (`[x]`). This will ensure a smooth and quick review process.
19 |
20 | - [ ] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
21 | - [ ] I updated/added relevant documentation (doc comments with `///`).
22 | - [ ] All existing and new tests are passing.
23 | - [ ] The analyzer (`flutter analyze --flutter-repo`) does not report any problems on my PR.
24 | - [ ] I am willing to follow-up on review comments in a timely manner.
25 |
26 | ## Breaking Change
27 |
28 | Did any tests fail when you ran them?
29 |
30 | - [ ] No, no existing tests failed, so this is *not* a breaking change.
31 | - [ ] Yes, this is a breaking change. *If not, delete the remainder of this section.*
32 | - [ ] I wrote a design doc: https://flutter.dev/go/template *Replace this with a link to your design doc's short link*
33 | - [ ] I got input from the developer relations team, specifically from: *Replace with the names of who gave advice*
34 | - [ ] I wrote a migration guide: *Replace with a link to your migration guide*
35 |
36 |
37 | [Test Coverage]: https://github.com/flutter/flutter/wiki/Test-coverage-for-package%3Aflutter
38 | [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
39 | [Features we expect every widget to implement]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#features-we-expect-every-widget-to-implement
40 |
--------------------------------------------------------------------------------
/.github/workflows/dart_build.yml:
--------------------------------------------------------------------------------
1 | name: build
2 |
3 | on:
4 | push:
5 | tags:
6 | - '[0-9]+.[0-9]+.[0-9]+'
7 |
8 | jobs:
9 | publish:
10 | environment: ${{ inputs.environment }}
11 | permissions:
12 | id-token: write
13 |
14 | runs-on: ubuntu-latest
15 |
16 | steps:
17 | - name: Checkout
18 | uses: actions/checkout@v4
19 |
20 | - name: 'Setup Dart'
21 | uses: dart-lang/setup-dart@v1
22 |
23 | - name: 'Get Packages'
24 | run: dart pub get
25 |
26 | - name: 'Dry Run Publishing'
27 | run: dart pub publish --dry-run
28 |
29 | - name: 'Publish Artifact'
30 | run: dart pub publish --force
31 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Files and directories created by pub
2 | .dart_tool/
3 | .packages
4 | # Remove the following pattern if you wish to check in your lock file
5 | pubspec.lock
6 |
7 | # Conventional directory for build outputs
8 | build/
9 |
10 | # Directory created by dartdoc
11 | doc/api/
12 |
--------------------------------------------------------------------------------
/AUTHORS:
--------------------------------------------------------------------------------
1 | # Below is a list of people and organizations that have contributed
2 | # to the MarchDev Toolkit projects. Names should be added to the list like so:
3 | #
4 | # Name/Organization
5 |
6 | MarchDev Toolkit
7 | - Oleh Marchenko
8 | - Elena Marchenko
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | ## 0.10.0
4 |
5 | * Updated dependencies (thanks to [@svoza10](https://github.com/svoza10))
6 | * Fixed [issue #9](https://github.com/marchdev-tk/google_directions_api/issues/9) (thanks to [@SamadiPour](https://github.com/SamadiPour))
7 | * Fixed [issue #12](https://github.com/marchdev-tk/google_directions_api/issues/12) (thanks to [@SamadiPour](https://github.com/SamadiPour))
8 | * Fixed [issue #16](https://github.com/marchdev-tk/google_directions_api/issues/16) (thanks to [@SamadiPour](https://github.com/SamadiPour))
9 |
10 | ## 0.9.1
11 |
12 | * Fixed misnaming of `duration_in_trafic`
13 |
14 | ## 0.9.0
15 |
16 | * Added null checks for `fromMap` constructors
17 |
18 | ## 0.8.0
19 |
20 | * Fixed waypoint order parsing
21 | * Added polyline parsing to `Step`
22 |
23 | ## 0.7.0
24 |
25 | * Fixed parsing of `instructions` (changed to `html_instructions`) for `Step`
26 | * Added language parameter to `DirectionsRequest`
27 |
28 | ## 0.6.0
29 |
30 | * Updated to NNBD
31 |
32 | ## 0.5.0
33 |
34 | * Redesigned LatLng, LatLngBounds due to ambiguous class names when using google_maps_flutter or google_maps packages
35 |
36 | ## 0.4.0
37 |
38 | * Removed flutter dependency
39 |
40 | ## 0.3.0
41 |
42 | * Finished with request models
43 | * Added LatLng, LatLngBounds to remove dependency on google_maps_flutter plugin
44 | * Added overviewPath getter for decoded overviewPolyline in DirectionsRoute
45 |
46 | ## 0.2.0
47 |
48 | * Redesigned class names of response DTO's
49 | * Doc updates
50 |
51 | ## 0.1.0
52 |
53 | * Implemented DirectionAPI responses
54 | * Added required request fields (origin/desctination/travelMode)
55 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as
6 | contributors and maintainers pledge to making participation in our project and
7 | our community a harassment-free experience for everyone, regardless of age, body
8 | size, disability, ethnicity, sex characteristics, gender identity and expression,
9 | level of experience, education, socio-economic status, nationality, personal
10 | appearance, race, religion, or sexual identity and orientation.
11 |
12 | ## Our Standards
13 |
14 | Examples of behavior that contributes to creating a positive environment
15 | include:
16 |
17 | * Using welcoming and inclusive language
18 | * Being respectful of differing viewpoints and experiences
19 | * Gracefully accepting constructive criticism
20 | * Focusing on what is best for the community
21 | * Showing empathy towards other community members
22 |
23 | Examples of unacceptable behavior by participants include:
24 |
25 | * The use of sexualized language or imagery and unwelcome sexual attention or
26 | advances
27 | * Trolling, insulting/derogatory comments, and personal or political attacks
28 | * Public or private harassment
29 | * Publishing others' private information, such as a physical or electronic
30 | address, without explicit permission
31 | * Other conduct which could reasonably be considered inappropriate in a
32 | professional setting
33 |
34 | ## Our Responsibilities
35 |
36 | Project maintainers are responsible for clarifying the standards of acceptable
37 | behavior and are expected to take appropriate and fair corrective action in
38 | response to any instances of unacceptable behavior.
39 |
40 | Project maintainers have the right and responsibility to remove, edit, or
41 | reject comments, commits, code, wiki edits, issues, and other contributions
42 | that are not aligned to this Code of Conduct, or to ban temporarily or
43 | permanently any contributor for other behaviors that they deem inappropriate,
44 | threatening, offensive, or harmful.
45 |
46 | ## Scope
47 |
48 | This Code of Conduct applies both within project spaces and in public spaces
49 | when an individual is representing the project or its community. Examples of
50 | representing a project or community include using an official project e-mail
51 | address, posting via an official social media account, or acting as an appointed
52 | representative at an online or offline event. Representation of a project may be
53 | further defined and clarified by project maintainers.
54 |
55 | ## Enforcement
56 |
57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
58 | reported by contacting the project team at eo.march.dev+support@gmail.com. All
59 | complaints will be reviewed and investigated and will result in a response that
60 | is deemed necessary and appropriate to the circumstances. The project team is
61 | obligated to maintain confidentiality with regard to the reporter of an incident.
62 | Further details of specific enforcement policies may be posted separately.
63 |
64 | Project maintainers who do not follow or enforce the Code of Conduct in good
65 | faith may face temporary or permanent repercussions as determined by other
66 | members of the project's leadership.
67 |
68 | ## Attribution
69 |
70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72 |
73 | [homepage]: https://www.contributor-covenant.org
74 |
75 | For answers to common questions about this code of conduct, see
76 | https://www.contributor-covenant.org/faq
77 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | When contributing to this repository, please first discuss the change you wish to make via issue,
4 | email, or any other method with the owners of this repository before making a change.
5 |
6 | Please note we have a code of conduct, please follow it in all your interactions with the project.
7 |
8 | ## Pull Request Process
9 |
10 | 1. Ensure any install or build dependencies are removed before the end of the layer when doing a
11 | build.
12 | 2. Update the README.md and CHANGELOG.md with details of changes to the interface, this includes new environment
13 | variables, exposed ports, useful file locations and container parameters.
14 | 3. Increase the version numbers in any examples files and the README.md to the new version that this
15 | Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/).
16 | 4. You may merge the Pull Request in once you have the sign-off of one other developer, or if you
17 | do not have permission to do that, you may request the second reviewer to merge it for you.
18 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | BSD 3-Clause License
2 |
3 | Copyright (c) 2021, MarchDev Toolkit
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions are met:
8 |
9 | 1. Redistributions of source code must retain the above copyright notice, this
10 | list of conditions and the following disclaimer.
11 |
12 | 2. Redistributions in binary form must reproduce the above copyright notice,
13 | this list of conditions and the following disclaimer in the documentation
14 | and/or other materials provided with the distribution.
15 |
16 | 3. Neither the name of the copyright holder nor the names of its
17 | contributors may be used to endorse or promote products derived from
18 | this software without specific prior written permission.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # google_directions_api
2 |
3 | 
4 | [](https://pub.dartlang.org/packages/google_directions_api)
5 | 
6 | 
7 |
8 | 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.
9 |
10 | ## Getting Started
11 |
12 | The Directions API is a service that calculates directions between locations using an HTTP request.
13 |
14 | With the Directions API, you can:
15 |
16 | * Search for directions for several modes of transportation, including transit, driving, walking or cycling.
17 | * Return multi-part directions using a series of waypoints.
18 | * 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.
19 |
20 | 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.
21 |
22 | **Note**: This service is **not designed to respond in real time to user input**.
23 |
24 | For full info about Directions API visit official [documentation](https://developers.google.com/maps/documentation/directions/intro#top_of_page)
25 |
26 | ### Usage
27 |
28 | ```dart
29 | import 'package:google_directions_api/google_directions_api.dart';
30 |
31 | void main() {
32 | DirectionsService.init('API_KEY');
33 |
34 | final directionsService = DirectionsService();
35 |
36 | final request = DirectionsRequest(
37 | origin: 'New York',
38 | destination: 'San Francisco',
39 | travelMode: TravelMode.driving,
40 | );
41 |
42 | directionsService.route(request,
43 | (DirectionsResult response, DirectionsStatus status) {
44 | if (status == DirectionsStatus.ok) {
45 | // do something with successful response
46 | } else {
47 | // do something with error response
48 | }
49 | });
50 | }
51 | ```
52 |
53 | ## Feature requests and Bug reports
54 |
55 | Feel free to post a feature requests or report a bug [here](https://github.com/marchdev-tk/google_directions_api/issues).
56 |
57 | ## TODO
58 |
59 | * Write tests via mocks
60 |
--------------------------------------------------------------------------------
/analysis_options.yaml:
--------------------------------------------------------------------------------
1 | include: package:flutter_lints/flutter.yaml
2 |
3 | linter:
4 | rules:
5 | avoid_print: false
6 | prefer_single_quotes: true
7 |
--------------------------------------------------------------------------------
/example/.gitignore:
--------------------------------------------------------------------------------
1 | # Files and directories created by pub
2 | .dart_tool/
3 | .packages
4 | # Remove the following pattern if you wish to check in your lock file
5 | pubspec.lock
6 |
7 | # Conventional directory for build outputs
8 | build/
9 |
10 | # Directory created by dartdoc
11 | doc/api/
12 |
--------------------------------------------------------------------------------
/example/README.md:
--------------------------------------------------------------------------------
1 | # google_directions_api_example
2 |
3 | Demonstrates how to use the google_directions_api package.
4 |
5 | ## Usage
6 |
7 | ```dart
8 | import 'package:google_directions_api/google_directions_api.dart';
9 |
10 | void main() {
11 | DirectionsService.init('API_KEY');
12 |
13 | final directinosService = DirectionsService();
14 |
15 | final request = DirectionsRequest(
16 | origin: 'Chicago, IL',
17 | destination: 'San Francisco, CA',
18 | travelMode: TravelMode.driving,
19 | );
20 |
21 | directinosService.route(request,
22 | (DirectionsResult response, DirectionsStatus status) {
23 | if (status == DirectionsStatus.ok) {
24 | // do something with successful response
25 | } else {
26 | // do something with error response
27 | }
28 | });
29 | }
30 | ```
31 |
32 | ## Getting Started
33 |
34 | For help getting started with Directions API, view
35 | [online documentation](https://developers.google.com/maps/documentation/directions/start), which offers tutorials,
36 | samples, guidance, and a full API reference.
37 |
--------------------------------------------------------------------------------
/example/bin/main.dart:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021, the MarchDev Toolkit project authors. Please see the AUTHORS file
2 | // for details. All rights reserved. Use of this source code is governed by a
3 | // BSD-style license that can be found in the LICENSE file.
4 |
5 | import 'package:google_directions_api/google_directions_api.dart';
6 |
7 | void main() {
8 | DirectionsService.init('API_KEY');
9 |
10 | final directionsService = DirectionsService();
11 |
12 | final request = DirectionsRequest(
13 | origin: 'New York',
14 | destination: 'San Francisco',
15 | travelMode: TravelMode.driving,
16 | );
17 |
18 | directionsService.route(request,
19 | (DirectionsResult response, DirectionsStatus? status) {
20 | if (status == DirectionsStatus.ok) {
21 | // do something with successful response
22 | } else {
23 | // do something with error response
24 | }
25 | });
26 | }
27 |
--------------------------------------------------------------------------------
/example/pubspec.yaml:
--------------------------------------------------------------------------------
1 | name: google_directions_api_example
2 | description: Example command line application of google_directions_api package.
3 |
4 | environment:
5 | sdk: '>=2.12.0 <3.0.0'
6 |
7 | dependencies:
8 | google_directions_api:
9 | path: ../
10 |
--------------------------------------------------------------------------------
/lib/google_directions_api.dart:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021, the MarchDev Toolkit project authors. Please see the AUTHORS file
2 | // for details. All rights reserved. Use of this source code is governed by a
3 | // BSD-style license that can be found in the LICENSE file.
4 |
5 | library google_directions_api;
6 |
7 | export 'src/directions.dart';
8 |
--------------------------------------------------------------------------------
/lib/src/directions.dart:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021, the MarchDev Toolkit project authors. Please see the AUTHORS file
2 | // for details. All rights reserved. Use of this source code is governed by a
3 | // BSD-style license that can be found in the LICENSE file.
4 |
5 | import 'dart:convert';
6 |
7 | import 'package:flinq/flinq.dart';
8 | import 'package:google_polyline_algorithm/google_polyline_algorithm.dart'
9 | as gpl;
10 | import 'package:http/http.dart' as http;
11 |
12 | part 'directions.request.dart';
13 | part 'directions.response.dart';
14 |
15 | /// This service is used to calculate route between two points
16 | class DirectionsService {
17 | static const _directionApiUrl =
18 | 'https://maps.googleapis.com/maps/api/directions/json';
19 |
20 | static String? _apiKey;
21 |
22 | /// Initializer of [GoogleMap].
23 | ///
24 | /// `Required` if `Directions API` on `Mobile device` will be needed.
25 | /// For other cases, could be ignored.
26 | static void init(String apiKey) => _apiKey = apiKey;
27 |
28 | /// Gets an google API key
29 | static String? get apiKey => _apiKey;
30 |
31 | /// Calculates route between two points.
32 | ///
33 | /// `request` argument contains origin and destination points
34 | /// and also settings for route calculation.
35 | ///
36 | /// `callback` argument will be called when route calculations finished.
37 | Future route(
38 | DirectionsRequest request,
39 | void Function(DirectionsResult, DirectionsStatus?) callback,
40 | ) async {
41 | final url = '$_directionApiUrl${request.toString()}&key=$apiKey';
42 | final response = await http.get(Uri.parse(url));
43 |
44 | if (response.statusCode != 200) {
45 | throw Exception(
46 | '${response.statusCode} (${response.reasonPhrase}), uri = ${response.request!.url}');
47 | }
48 |
49 | final result = DirectionsResult.fromMap(json.decode(response.body));
50 |
51 | callback(result, result.status);
52 | }
53 | }
54 |
55 | /// A pair of latitude and longitude coordinates, stored as degrees.
56 | class GeoCoord {
57 | /// Creates a geographical location specified in degrees [latitude] and
58 | /// [longitude].
59 | ///
60 | /// The latitude is clamped to the inclusive interval from -90.0 to +90.0.
61 | ///
62 | /// The longitude is normalized to the half-open interval from -180.0
63 | /// (inclusive) to +180.0 (exclusive)
64 | const GeoCoord(double latitude, double longitude)
65 | : latitude =
66 | (latitude < -90.0 ? -90.0 : (90.0 < latitude ? 90.0 : latitude)),
67 | longitude = (longitude + 180.0) % 360.0 - 180.0;
68 |
69 | /// The latitude in degrees between -90.0 and 90.0, both inclusive.
70 | final double latitude;
71 |
72 | /// The longitude in degrees between -180.0 (inclusive) and 180.0 (exclusive).
73 | final double longitude;
74 |
75 | static GeoCoord _fromList(List list) => GeoCoord(
76 | list[0] as double,
77 | list[1] as double,
78 | );
79 |
80 | @override
81 | String toString() => '$runtimeType($latitude, $longitude)';
82 |
83 | @override
84 | bool operator ==(Object other) {
85 | return other is GeoCoord &&
86 | other.latitude == latitude &&
87 | other.longitude == longitude;
88 | }
89 |
90 | @override
91 | int get hashCode => latitude.hashCode + longitude.hashCode;
92 | }
93 |
94 | /// A latitude/longitude aligned rectangle.
95 | ///
96 | /// The rectangle conceptually includes all points (lat, lng) where
97 | /// * lat ∈ [`southwest.latitude`, `northeast.latitude`]
98 | /// * lng ∈ [`southwest.longitude`, `northeast.longitude`],
99 | /// if `southwest.longitude` ≤ `northeast.longitude`,
100 | /// * lng ∈ [-180, `northeast.longitude`] ∪ [`southwest.longitude`, 180],
101 | /// if `northeast.longitude` < `southwest.longitude`
102 | class GeoCoordBounds {
103 | /// Creates geographical bounding box with the specified corners.
104 | ///
105 | /// The latitude of the southwest corner cannot be larger than the
106 | /// latitude of the northeast corner.
107 | GeoCoordBounds({required this.southwest, required this.northeast})
108 | : assert(southwest.latitude <= northeast.latitude);
109 |
110 | /// The southwest corner of the rectangle.
111 | final GeoCoord southwest;
112 |
113 | /// The northeast corner of the rectangle.
114 | final GeoCoord northeast;
115 |
116 | /// Returns whether this rectangle contains the given [GeoCoord].
117 | bool contains(GeoCoord point) {
118 | return _containsLatitude(point.latitude) &&
119 | _containsLongitude(point.longitude);
120 | }
121 |
122 | bool _containsLatitude(double lat) {
123 | return (southwest.latitude <= lat) && (lat <= northeast.latitude);
124 | }
125 |
126 | bool _containsLongitude(double lng) {
127 | if (southwest.longitude <= northeast.longitude) {
128 | return southwest.longitude <= lng && lng <= northeast.longitude;
129 | } else {
130 | return southwest.longitude <= lng || lng <= northeast.longitude;
131 | }
132 | }
133 |
134 | @override
135 | String toString() {
136 | return '$runtimeType($southwest, $northeast)';
137 | }
138 |
139 | @override
140 | bool operator ==(Object other) {
141 | return other is GeoCoordBounds &&
142 | other.southwest == southwest &&
143 | other.northeast == northeast;
144 | }
145 |
146 | @override
147 | int get hashCode => southwest.hashCode + northeast.hashCode;
148 | }
149 |
150 | /// Represents an enum of various travel modes.
151 | ///
152 | /// The valid travel modes that can be specified in a
153 | /// `DirectionsRequest` as well as the travel modes returned
154 | /// in a `DirectionsStep`. Specify these by value, or by using
155 | /// the constant's name.
156 | class TravelMode {
157 | const TravelMode(this._name);
158 |
159 | final String _name;
160 |
161 | static final values = [bicycling, driving, transit, walking];
162 |
163 | /// Specifies a bicycling directions request.
164 | static const bicycling = TravelMode('BICYCLING');
165 |
166 | /// Specifies a driving directions request.
167 | static const driving = TravelMode('DRIVING');
168 |
169 | /// Specifies a transit directions request.
170 | static const transit = TravelMode('TRANSIT');
171 |
172 | /// Specifies a walking directions request.
173 | static const walking = TravelMode('WALKING');
174 |
175 | @override
176 | int get hashCode => _name.hashCode;
177 |
178 | @override
179 | bool operator ==(dynamic other) =>
180 | other is TravelMode && _name == other._name;
181 |
182 | @override
183 | String toString() => _name;
184 | }
185 |
--------------------------------------------------------------------------------
/lib/src/directions.request.dart:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021, the MarchDev Toolkit project authors. Please see the AUTHORS file
2 | // for details. All rights reserved. Use of this source code is governed by a
3 | // BSD-style license that can be found in the LICENSE file.
4 |
5 | part of 'directions.dart';
6 |
7 | String _addIfNotNull(String name, dynamic value) =>
8 | value == null ? '' : '&$name=$value';
9 |
10 | String _convertLocation(dynamic location) {
11 | if (location is GeoCoord) {
12 | return '${location.latitude},${location.longitude}';
13 | } else if (location is String &&
14 | (location.startsWith('place_id:') || location.startsWith('enc:'))) {
15 | return location;
16 | } else if (location is String) {
17 | location = location.replaceAll(', ', ',');
18 | return location
19 | .split(' ')
20 | .where((dynamic _) => _.trim().isNotEmpty == true)
21 | .join('+');
22 | }
23 |
24 | throw UnsupportedError(
25 | 'Unsupported type of argument: ${location.runtimeType}');
26 | }
27 |
28 | /// Settings for route calculation.
29 | ///
30 | /// `origin` and `destination` arguments are required.
31 | class DirectionsRequest {
32 | const DirectionsRequest({
33 | required this.origin,
34 | required this.destination,
35 | this.travelMode,
36 | this.optimizeWaypoints,
37 | this.waypoints,
38 | this.alternatives,
39 | this.avoidTolls,
40 | this.avoidHighways,
41 | this.avoidFerries,
42 | this.avoidIndoor,
43 | this.unitSystem,
44 | this.region,
45 | this.drivingOptions,
46 | this.transitOptions,
47 | this.language,
48 | });
49 |
50 | /// The address, textual latitude/longitude value, or place ID
51 | /// from which you wish to calculate directions.
52 | ///
53 | /// This field is required.
54 | ///
55 | /// * If you pass an **address**, the Directions service geocodes
56 | /// the string and converts it to a latitude/longitude
57 | /// coordinate to calculate directions. This coordinate may be
58 | /// different from that returned by the Geocoding API, for
59 | /// example a building entrance rather than its center.
60 | ///
61 | /// ```origin=24+Sussex+Drive+Ottawa+ON```
62 | ///
63 | /// * If you pass **coordinates**, they are used unchanged to
64 | /// calculate directions. Ensure that no space exists between
65 | /// the latitude and longitude values.
66 | ///
67 | /// ```origin=41.43206,-81.38992```
68 | ///
69 | /// * Place IDs must be prefixed with place_id:. The place ID
70 | /// may only be specified if the request includes an API key or
71 | /// a Google Maps Platform Premium Plan client ID. You can
72 | /// retrieve place IDs from the Geocoding API and the Places
73 | /// API (including Place Autocomplete). For an example using
74 | /// place IDs from Place Autocomplete, see
75 | /// [Place Autocomplete and Directions][place_info]. For more
76 | /// place IDs, see the [Place ID overview][place_overview].
77 | ///
78 | /// ```origin=place_id:ChIJ3S-JXmauEmsRUcIaWtf4MzE```
79 | ///
80 | /// [place_info]: https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-directions
81 | /// [place_overview]: https://developers.google.com/places/place-id
82 | final dynamic origin;
83 |
84 | /// The address, textual latitude/longitude value, or place ID
85 | /// to which you wish to calculate directions. The options for
86 | /// the destination parameter are the same as for the [origin]
87 | /// parameter, described above.
88 | ///
89 | /// This field is required.
90 | final dynamic destination;
91 |
92 | /// Specifies the mode of transport to use when calculating
93 | /// directions. Valid values and other request details are
94 | /// specified in [TravelModes].
95 | ///
96 | /// Default value is [TravelMode.driving]
97 | final TravelMode? travelMode;
98 |
99 | /// Specifies an array of intermediate locations to include
100 | /// along the route between the origin and destination points
101 | /// as pass through or stopover locations. Waypoints alter a
102 | /// route by directing it through the specified location(s).
103 | /// The API supports waypoints for these travel modes: driving,
104 | /// walking and bicycling; not transit.
105 | ///
106 | /// You can specify waypoints using the following values:
107 | ///
108 | /// * Latitude/longitude coordinates (`lat`/`lng`): an explicit value
109 | /// pair. (`-34.92788%2C138.60008` comma, no space)
110 | /// * Place ID: The unique value specific to a location.
111 | /// * Address string (`Charlestown, Boston,MA`)
112 | /// * Encoded polyline that can be specified by a set of any of
113 | /// the above. (`enc:lexeF{~wsZejrPjtye@:`)
114 | final List? waypoints;
115 |
116 | /// By default, the Directions service calculates a route through
117 | /// the provided waypoints in their given order.
118 | ///
119 | /// If set to `true` will allow the Directions service to optimize
120 | /// the provided route by rearranging the waypoints in a more
121 | /// efficient order. (This optimization is an application of the
122 | /// [traveling salesperson problem][tsp].) Travel time is the primary
123 | /// factor which is optimized, but other factors such as distance,
124 | /// number of turns and many more may be taken into account when
125 | /// deciding which route is the most efficient. All waypoints must
126 | /// be stopovers for the Directions service to optimize their route.
127 | ///
128 | /// If you instruct the Directions service to optimize the order of
129 | /// its waypoints, their order will be returned in the waypoint_order
130 | /// field within the [DirectionsRoute] object. The `waypointOrder`
131 | /// field returns values which are zero-based.
132 | ///
133 | /// [tsp]: https://en.wikipedia.org/wiki/Travelling_salesman_problem
134 | final bool? optimizeWaypoints;
135 |
136 | /// If set to `true`, specifies that the Directions service may
137 | /// provide more than one route alternative in the response.
138 | /// Note that providing route alternatives may increase the
139 | /// response time from the server. This is only available for
140 | /// requests without intermediate waypoints.
141 | final bool? alternatives;
142 |
143 | /// Indicates that the calculated route should avoid toll
144 | /// roads/bridges.
145 | final bool? avoidTolls;
146 |
147 | /// Indicates that the calculated route should avoid highways.
148 | final bool? avoidHighways;
149 |
150 | /// Indicates that the calculated route should avoid ferries.
151 | final bool? avoidFerries;
152 |
153 | /// Indicates that the calculated route should avoid indoor
154 | /// steps for walking and transit directions.
155 | final bool? avoidIndoor;
156 |
157 | /// Specifies the region code, specified as a ccTLD
158 | /// ("top-level domain") two-character value.
159 | ///
160 | /// You can set the Directions service to return results from
161 | /// a specific region by using the `region` parameter. This
162 | /// parameter takes a [ccTLD][cctld] (country code top-level domain)
163 | /// argument specifying the region bias. Most ccTLD codes are
164 | /// identical to ISO 3166-1 codes, with some notable exceptions.
165 | /// For example, the United Kingdom's ccTLD is "uk" (`.co.uk`)
166 | /// while its ISO 3166-1 code is "gb" (technically for the entity
167 | /// of "The United Kingdom of Great Britain and Northern Ireland").
168 | ///
169 | /// You may utilize any domain in which the main Google Maps
170 | /// application has launched driving directions.
171 | ///
172 | /// [cctld]: https://en.wikipedia.org/wiki/Country_code_top-level_domain
173 | final String? region;
174 |
175 | /// Specifies the unit system to use when displaying results.
176 | final UnitSystem? unitSystem;
177 |
178 | /// Specifies the desired time of departure and/or desired assumption
179 | /// of time in traffic calculation for `non-transit` [TravelMode].
180 | final DrivingOptions? drivingOptions;
181 |
182 | /// Specifies the desired time of arrival/departure and/or desired
183 | /// transit types and/or desired routing preference for `transit`
184 | /// [TravelMode].
185 | final TransitOptions? transitOptions;
186 |
187 | /// The language in which to return results
188 | /// If language is not supplied, the API attempts to use the preferred
189 | /// language as specified in the Accept-Language header, or the native
190 | /// language of the domain from which the request is sent.
191 | /// For a complete list of the supported languages visit
192 | /// https://developers.google.com/maps/faq#languagesupport
193 | final String? language;
194 |
195 | String? _convertAvoids() {
196 | final avoids = [];
197 |
198 | if (avoidTolls == true) {
199 | avoids.add('tolls');
200 | }
201 | if (avoidHighways == true) {
202 | avoids.add('highways');
203 | }
204 | if (avoidFerries == true) {
205 | avoids.add('ferries');
206 | }
207 | if (avoidIndoor == true) {
208 | avoids.add('indoor');
209 | }
210 |
211 | return avoids.isEmpty ? null : avoids.join('|');
212 | }
213 |
214 | String? _convertWaypoints() {
215 | if (waypoints?.isEmpty != false) return null;
216 |
217 | return (optimizeWaypoints == true ? 'optimize:true|' : '') +
218 | waypoints!.mapList((_) => _.toString()).join('|');
219 | }
220 |
221 | @override
222 | String toString() => '?origin=${_convertLocation(origin)}&'
223 | 'destination=${_convertLocation(destination)}'
224 | '${_addIfNotNull('mode', travelMode?.toString().toLowerCase())}'
225 | '${_addIfNotNull('waypoints', _convertWaypoints())}'
226 | '${_addIfNotNull('alternatives', alternatives)}'
227 | '${_addIfNotNull('avoid', _convertAvoids())}'
228 | '${_addIfNotNull('units', unitSystem)}'
229 | '${_addIfNotNull('region', region)}'
230 | '${_addIfNotNull('language', language)}'
231 | '${drivingOptions == null ? '' : drivingOptions.toString()}'
232 | '${transitOptions == null ? '' : transitOptions.toString()}';
233 | }
234 |
235 | /// Specifies an intermediate location to include along the route
236 | /// between the origin and destination points as pass through
237 | /// or stopover location. Waypoints alter a route by directing it
238 | /// through the specified location(s).
239 | ///
240 | /// The API **supports** waypoints for these travel modes: `driving`,
241 | /// `walking` and `bicycling`; `not transit`.
242 | /// You can specify waypoints using the following values:
243 | ///
244 | /// * `location` - specifies an intermediate location to include
245 | /// along the route between the origin and destination points.
246 | /// Waypoints alter a route by directing it through the specified
247 | /// location(s).
248 | ///
249 | /// You can specify waypoints using the following values:
250 | ///
251 | /// * Latitude/longitude coordinates (`lat`/`lng`): an explicit value
252 | /// pair. (`-34.92788%2C138.60008` comma, no space)
253 | /// * Place ID: The unique value specific to a location.
254 | /// * Address string (`Charlestown, Boston,MA`)
255 | /// * Encoded polyline that can be specified
256 | ///
257 | /// * `stopover` - influence routes with stopover and pass through
258 | /// points For each waypoint in the request, the directions response
259 | /// appends an entry to the `legs` array to provide the details
260 | /// for stopovers on that leg of the journey.
261 | ///
262 | /// If you'd like to influence the route using waypoints without
263 | /// adding a stopover, prefix `via:` will be added to the waypoint.
264 | /// Waypoints prefixed with via: will not add an entry to the
265 | /// `legs` array, but will route the journey through the waypoint.
266 | class DirectionsWaypoint {
267 | const DirectionsWaypoint({
268 | this.location,
269 | this.stopover = true,
270 | });
271 |
272 | /// Specifies an intermediate location to include along the route
273 | /// between the origin and destination points. Waypoints alter a
274 | /// route by directing it through the specified location(s).
275 | ///
276 | /// You can specify waypoints using the following values:
277 | ///
278 | /// * Latitude/longitude coordinates (`lat`/`lng`): an explicit value
279 | /// pair. (`-34.92788,138.60008` comma or `%2C`, no space)
280 | /// * Place ID: The unique value specific to a location.
281 | /// * Address string (`Charlestown, Boston,MA`)
282 | /// * Encoded polyline that can be specified by a set of any of
283 | /// the above. (`enc:lexeF{~wsZejrPjtye@:`)
284 | final dynamic location;
285 |
286 | /// Influence routes with stopover and pass through points
287 | /// For each waypoint in the request, the directions response
288 | /// appends an entry to the `legs` array to provide the details
289 | /// for stopovers on that leg of the journey.
290 | ///
291 | /// If you'd like to influence the route using waypoints without
292 | /// adding a stopover, prefix `via:` will be added to the waypoint.
293 | /// Waypoints prefixed with via: will not add an entry to the
294 | /// `legs` array, but will route the journey through the waypoint.
295 | final bool stopover;
296 |
297 | @override
298 | String toString() =>
299 | '${stopover == true ? '' : 'via:'}${_convertLocation(location)}';
300 | }
301 |
302 | /// Specifies the desired time of arrival/departure and/or desired
303 | /// transit types and/or desired routing preference for `transit`
304 | /// [TravelMode].
305 | ///
306 | /// May contain the following fields:
307 | ///
308 | /// * `arrivalTime` - specifies the desired time of arrival for
309 | /// transit directions. You can specify either `departureTime` or
310 | /// `arrivalTime`, but not both.
311 | ///
312 | ///
313 | /// * `departureTime` - specifies the desired time of departure.
314 | /// The departure time may be specified in two cases:
315 | ///
316 | /// * For requests where the travel mode is `transit`: You can
317 | /// optionally specify one of `departureTime` or `arrivalTime`.
318 | /// If neither time is specified, the `departureTime` defaults to
319 | /// now (that is, the departure time defaults to the current time).
320 | ///
321 | /// * For requests where the travel mode is `driving`: You can
322 | /// specify the `departureTime` to receive a route and trip
323 | /// duration (response field: `durationInTraffic`) that take
324 | /// traffic conditions into account. The `departureTime` must be
325 | /// set to the current time or some time in the future. It
326 | /// cannot be in the past.
327 | ///
328 | /// Note: If departure time is not specified, choice of route and
329 | /// duration are based on road network and average time-independent
330 | /// traffic conditions. Results for a given request may vary over
331 | /// time due to changes in the road network, updated average traffic
332 | /// conditions, and the distributed nature of the service. Results
333 | /// may also vary between nearly-equivalent routes at any time or
334 | /// frequency.
335 | ///
336 | ///
337 | /// * `mode` - specifies one or more preferred modes of transit.
338 | /// This parameter may only be specified for transit directions. The
339 | /// parameter supports the following arguments:
340 | ///
341 | /// * `bus` indicates that the calculated route should prefer travel
342 | /// by bus.
343 | /// * `subway` indicates that the calculated route should prefer
344 | /// travel by subway.
345 | /// * `train` indicates that the calculated route should prefer
346 | /// travel by train.
347 | /// * `tram` indicates that the calculated route should prefer travel
348 | /// by tram and light rail.
349 | /// * `rail` indicates that the calculated route should prefer travel
350 | /// by train, tram, light rail, and subway. This is equivalent to
351 | /// `transitMode=train|tram|subway`.
352 | ///
353 | ///
354 | /// * `routingPreference` - specifies preferences for transit routes.
355 | /// Using this parameter, you can bias the options returned, rather than
356 | /// accepting the default best route chosen by the API. This parameter
357 | /// may only be specified for transit directions. The parameter supports
358 | /// the following arguments:
359 | ///
360 | /// * `lessWalking` indicates that the calculated route should
361 | /// prefer limited amounts of walking.
362 | /// * `fewerTransfers` indicates that the calculated route should
363 | /// prefer a limited number of transfers.
364 | class TransitOptions {
365 | const TransitOptions({
366 | this.arrivalTime,
367 | this.departureTime,
368 | this.modes,
369 | this.routingPreference,
370 | });
371 |
372 | /// Specifies the desired time of arrival for transit directions.
373 | /// You can specify either `departureTime` or `arrivalTime`, but
374 | /// not both.
375 | final DateTime? arrivalTime;
376 |
377 | /// Specifies the desired time of departure. The departure time
378 | /// may be specified in two cases:
379 | ///
380 | /// * For requests where the travel mode is `transit`: You can
381 | /// optionally specify one of `departureTime` or `arrivalTime`.
382 | /// If neither time is specified, the `departureTime` defaults to
383 | /// now (that is, the departure time defaults to the current time).
384 | ///
385 | /// * For requests where the travel mode is `driving`: You can
386 | /// specify the `departureTime` to receive a route and trip
387 | /// duration (response field: `durationInTraffic`) that take
388 | /// traffic conditions into account. The `departureTime` must be
389 | /// set to the current time or some time in the future. It
390 | /// cannot be in the past.
391 | ///
392 | /// Note: If departure time is not specified, choice of route and
393 | /// duration are based on road network and average time-independent
394 | /// traffic conditions. Results for a given request may vary over
395 | /// time due to changes in the road network, updated average traffic
396 | /// conditions, and the distributed nature of the service. Results
397 | /// may also vary between nearly-equivalent routes at any time or
398 | /// frequency.
399 | final DateTime? departureTime;
400 |
401 | /// Specifies one or more preferred modes of transit. This parameter
402 | /// may only be specified for transit directions. The parameter
403 | /// supports the following arguments:
404 | ///
405 | /// * `bus` indicates that the calculated route should prefer travel
406 | /// by bus.
407 | /// * `subway` indicates that the calculated route should prefer
408 | /// travel by subway.
409 | /// * `train` indicates that the calculated route should prefer
410 | /// travel by train.
411 | /// * `tram` indicates that the calculated route should prefer travel
412 | /// by tram and light rail.
413 | /// * `rail` indicates that the calculated route should prefer travel
414 | /// by train, tram, light rail, and subway. This is equivalent to
415 | /// `transitMode=train|tram|subway`.
416 | final List? modes;
417 |
418 | /// Specifies preferences for transit routes. Using this parameter,
419 | /// you can bias the options returned, rather than accepting the
420 | /// default best route chosen by the API. This parameter may only
421 | /// be specified for transit directions. The parameter supports the
422 | /// following arguments:
423 | ///
424 | /// * `lessWalking` indicates that the calculated route should
425 | /// prefer limited amounts of walking.
426 | /// * `fewerTransfers` indicates that the calculated route should
427 | /// prefer a limited number of transfers.
428 | final TransitRoutingPreference? routingPreference;
429 |
430 | @override
431 | String toString() =>
432 | '${_addIfNotNull('arrival_time', arrivalTime?.millisecondsSinceEpoch)}'
433 | '${_addIfNotNull('departure_time', departureTime?.millisecondsSinceEpoch)}'
434 | '${_addIfNotNull('transit_mode', modes?.map((_) => _.toString()).join('|'))}'
435 | '${_addIfNotNull('transit_routing_preference', routingPreference)}';
436 | }
437 |
438 | /// Specifies the desired time of departure and/or desired assumption
439 | /// of time in traffic calculation for `non-transit` [TravelMode].
440 | ///
441 | /// May contain the following fields:
442 | ///
443 | /// * `departureTime` - specifies the desired time of departure.
444 | /// The departure time may be specified in two cases:
445 | ///
446 | /// * For requests where the travel mode is `transit`: You can
447 | /// optionally specify one of `departureTime` or `arrivalTime`.
448 | /// If neither time is specified, the `departureTime` defaults to
449 | /// now (that is, the departure time defaults to the current time).
450 | ///
451 | /// * For requests where the travel mode is `driving`: You can
452 | /// specify the `departureTime` to receive a route and trip
453 | /// duration (response field: `durationInTraffic`) that take
454 | /// traffic conditions into account. The `departureTime` must be
455 | /// set to the current time or some time in the future. It
456 | /// cannot be in the past.
457 | ///
458 | /// Note: If departure time is not specified, choice of route and
459 | /// duration are based on road network and average time-independent
460 | /// traffic conditions. Results for a given request may vary over
461 | /// time due to changes in the road network, updated average traffic
462 | /// conditions, and the distributed nature of the service. Results
463 | /// may also vary between nearly-equivalent routes at any time or
464 | /// frequency.
465 | ///
466 | ///
467 | /// * `trafficModel` - specifies the assumptions to use when calculating
468 | /// time in traffic. This setting affects the value returned in the
469 | /// `durationInTraffic` field in the response, which contains the predicted
470 | /// time in traffic based on historical averages. The `trafficModel`
471 | /// parameter may only be specified for driving directions where
472 | /// the request includes a `departureTime`.
473 | ///
474 | /// The available values for this parameter are:
475 | ///
476 | /// * `bestGuess` (default) indicates that the returned `durationInTraffic`
477 | /// should be the best estimate of travel time given what is known about
478 | /// both historical traffic conditions and live traffic. Live traffic
479 | /// becomes more important the closer the `departureTime` is to now.
480 | /// * `pessimistic` indicates that the returned `durationInTraffic`
481 | /// should be longer than the actual travel time on most days, though
482 | /// occasional days with particularly bad traffic conditions may
483 | /// exceedthis value.
484 | /// * `optimistic` indicates that the returned `durationInTraffic`
485 | /// should be shorter than the actual travel time on most days, though
486 | /// occasional days with particularly good traffic conditions may be
487 | /// faster than this value.
488 | ///
489 | /// The default value of `bestGuess` will give the most useful
490 | /// predictions for the vast majority of use cases. It is possible
491 | /// the `bestGuess` travel time prediction may be shorter than
492 | /// `optimistic`, or alternatively, longer than `pessimistic`, due to
493 | /// the way the `bestGuess` prediction model integrates live traffic
494 | /// information.
495 | class DrivingOptions {
496 | const DrivingOptions({
497 | this.departureTime,
498 | this.trafficModel,
499 | });
500 |
501 | /// Specifies the desired time of departure. The departure time
502 | /// may be specified in two cases:
503 | ///
504 | /// * For requests where the travel mode is `transit`: You can
505 | /// optionally specify one of `departureTime` or `arrivalTime`.
506 | /// If neither time is specified, the `departureTime` defaults to
507 | /// now (that is, the departure time defaults to the current time).
508 | ///
509 | /// * For requests where the travel mode is `driving`: You can
510 | /// specify the `departureTime` to receive a route and trip
511 | /// duration (response field: `durationInTraffic`) that take
512 | /// traffic conditions into account. The `departureTime` must be
513 | /// set to the current time or some time in the future. It
514 | /// cannot be in the past.
515 | ///
516 | /// Note: If departure time is not specified, choice of route and
517 | /// duration are based on road network and average time-independent
518 | /// traffic conditions. Results for a given request may vary over
519 | /// time due to changes in the road network, updated average traffic
520 | /// conditions, and the distributed nature of the service. Results
521 | /// may also vary between nearly-equivalent routes at any time or
522 | /// frequency.
523 | final DateTime? departureTime;
524 |
525 | /// Specifies the assumptions to use when calculating time in traffic.
526 | /// This setting affects the value returned in the `durationInTraffic`
527 | /// field in the response, which contains the predicted time in
528 | /// traffic based on historical averages. The `trafficModel`
529 | /// parameter may only be specified for driving directions where
530 | /// the request includes a `departureTime`.
531 | ///
532 | /// Defaults to `bestGuess`.
533 | ///
534 | /// The available values for this parameter are:
535 | ///
536 | /// * `bestGuess` (default) indicates that the returned `durationInTraffic`
537 | /// should be the best estimate of travel time given what is known about
538 | /// both historical traffic conditions and live traffic. Live traffic
539 | /// becomes more important the closer the `departureTime` is to now.
540 | /// * `pessimistic` indicates that the returned `durationInTraffic`
541 | /// should be longer than the actual travel time on most days, though
542 | /// occasional days with particularly bad traffic conditions may
543 | /// exceedthis value.
544 | /// * `optimistic` indicates that the returned `durationInTraffic`
545 | /// should be shorter than the actual travel time on most days, though
546 | /// occasional days with particularly good traffic conditions may be
547 | /// faster than this value.
548 | ///
549 | /// The default value of `bestGuess` will give the most useful
550 | /// predictions for the vast majority of use cases. It is possible
551 | /// the `bestGuess` travel time prediction may be shorter than
552 | /// `optimistic`, or alternatively, longer than `pessimistic`, due to
553 | /// the way the `bestGuess` prediction model integrates live traffic
554 | /// information.
555 | final TrafficModel? trafficModel;
556 |
557 | @override
558 | String toString() =>
559 | '${_addIfNotNull('departure_time', departureTime?.millisecondsSinceEpoch)}'
560 | '${_addIfNotNull('traffic_model', trafficModel)}';
561 | }
562 |
563 | /// Directions results contain `text` within `distance` fields
564 | /// that may be displayed to the user to indicate the distance
565 | /// of a particular "step" of the route. By default, this text
566 | /// uses the unit system of the origin's country or region.
567 | ///
568 | /// For example, a route from "Chicago, IL" to "Toronto, ONT"
569 | /// will display results in miles, while the reverse route will
570 | /// display results in kilometers. You may override this unit
571 | /// system by setting one explicitly within the request's units
572 | /// parameter, passing one of the following values:
573 | ///
574 | /// `metric` specifies usage of the metric system. Textual
575 | /// distances are returned using kilometers and meters.
576 | /// `imperial` specifies usage of the Imperial (English)
577 | /// system. Textual distances are returned using miles and feet.
578 | ///
579 | /// Note: this unit system setting only affects the text displayed
580 | /// within distance fields. The distance fields also contain values
581 | /// which are always expressed in meters.
582 | class UnitSystem {
583 | const UnitSystem(this._name);
584 |
585 | final String _name;
586 |
587 | static final values = [imperial, metric];
588 |
589 | /// Specifies usage of the metric system. Textual distances are
590 | /// returned using kilometers and meters.
591 | static const imperial = UnitSystem('IMPERIAL');
592 |
593 | /// Specifies usage of the Imperial (English) system. Textual
594 | /// distances are returned using miles and feet.
595 | static const metric = UnitSystem('METRIC');
596 |
597 | @override
598 | String toString() => _name;
599 | }
600 |
601 | /// Specifies one or more preferred modes of transit. This parameter
602 | /// may only be specified for transit directions. The parameter
603 | /// supports the following arguments:
604 | ///
605 | /// * `bus` indicates that the calculated route should prefer travel
606 | /// by bus.
607 | /// * `subway` indicates that the calculated route should prefer
608 | /// travel by subway.
609 | /// * `train` indicates that the calculated route should prefer
610 | /// travel by train.
611 | /// * `tram` indicates that the calculated route should prefer travel
612 | /// by tram and light rail.
613 | /// * `rail` indicates that the calculated route should prefer travel
614 | /// by train, tram, light rail, and subway. This is equivalent to
615 | /// `transitMode=train|tram|subway`.
616 | class TransitMode {
617 | const TransitMode(this._name);
618 |
619 | final String _name;
620 |
621 | static final values = [
622 | bus,
623 | subway,
624 | train,
625 | tram,
626 | rail,
627 | ];
628 |
629 | /// Indicates that the calculated route should prefer travel
630 | /// by bus.
631 | static const bus = TransitMode('bus');
632 |
633 | /// Indicates that the calculated route should prefer travel
634 | /// by bus.
635 | static const subway = TransitMode('subway');
636 |
637 | /// Indicates that the calculated route should prefer travel
638 | /// by bus.
639 | static const train = TransitMode('train');
640 |
641 | /// Indicates that the calculated route should prefer travel
642 | /// by bus.
643 | static const tram = TransitMode('tram');
644 |
645 | /// Indicates that the calculated route should prefer travel
646 | /// by bus.
647 | static const rail = TransitMode('rail');
648 |
649 | @override
650 | String toString() => _name;
651 | }
652 |
653 | /// Specifies preferences for transit routes. Using this parameter,
654 | /// you can bias the options returned, rather than accepting the
655 | /// default best route chosen by the API. This parameter may only
656 | /// be specified for transit directions. The parameter supports the
657 | /// following arguments:
658 | ///
659 | /// * `lessWalking` indicates that the calculated route should
660 | /// prefer limited amounts of walking.
661 | /// * `fewerTransfers` indicates that the calculated route should
662 | /// prefer a limited number of transfers.
663 | class TransitRoutingPreference {
664 | const TransitRoutingPreference(this._name);
665 |
666 | final String _name;
667 |
668 | static final values = [lessWalking, fewerTransfers];
669 |
670 | /// Indicates that the calculated route should prefer limited
671 | /// amounts of walking.
672 | static const lessWalking = TransitRoutingPreference('less_walking');
673 |
674 | /// Indicates that the calculated route should prefer a limited
675 | /// number of transfers
676 | static const fewerTransfers = TransitRoutingPreference('fewer_transfers');
677 |
678 | @override
679 | String toString() => _name;
680 | }
681 |
682 | /// Specifies the assumptions to use when calculating time in traffic.
683 | /// This setting affects the value returned in the `durationInTraffic`
684 | /// field in the response, which contains the predicted time in
685 | /// traffic based on historical averages. The `trafficModel`
686 | /// parameter may only be specified for driving directions where
687 | /// the request includes a `departureTime`.
688 | ///
689 | /// The available values for this parameter are:
690 | ///
691 | /// * `bestGuess` indicates that the returned `durationInTraffic`
692 | /// should be the best estimate of travel time given what is known about
693 | /// both historical traffic conditions and live traffic. Live traffic
694 | /// becomes more important the closer the `departureTime` is to now.
695 | /// * `pessimistic` indicates that the returned `durationInTraffic`
696 | /// should be longer than the actual travel time on most days, though
697 | /// occasional days with particularly bad traffic conditions may
698 | /// exceedthis value.
699 | /// * `optimistic` indicates that the returned `durationInTraffic`
700 | /// should be shorter than the actual travel time on most days, though
701 | /// occasional days with particularly good traffic conditions may be
702 | /// faster than this value.
703 | class TrafficModel {
704 | const TrafficModel(this._name);
705 |
706 | final String _name;
707 |
708 | static final values = [
709 | bestGuess,
710 | pessimistic,
711 | ];
712 |
713 | /// Indicates that the returned `durationInTraffic`
714 | /// should be the best estimate of travel time given what is known about
715 | /// both historical traffic conditions and live traffic. Live traffic
716 | /// becomes more important the closer the `departureTime` is to now.
717 | static const bestGuess = TrafficModel('best_guess');
718 |
719 | /// Indicates that the returned `durationInTraffic`
720 | /// should be longer than the actual travel time on most days, though
721 | /// occasional days with particularly bad traffic conditions may
722 | /// exceedthis value.
723 | static const pessimistic = TrafficModel('pessimistic');
724 |
725 | /// Indicates that the returned `durationInTraffic`
726 | /// should be shorter than the actual travel time on most days, though
727 | /// occasional days with particularly good traffic conditions may be
728 | /// faster than this value.
729 | static const optimistic = TrafficModel('optimistic');
730 |
731 | @override
732 | String toString() => _name;
733 | }
734 |
--------------------------------------------------------------------------------
/lib/src/directions.response.dart:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021, the MarchDev Toolkit project authors. Please see the AUTHORS file
2 | // for details. All rights reserved. Use of this source code is governed by a
3 | // BSD-style license that can be found in the LICENSE file.
4 |
5 | part of 'directions.dart';
6 |
7 | GeoCoord? _getGeoCoordFromMap(Map? map) => map == null
8 | ? null
9 | : GeoCoord(
10 | double.parse(map['lat'].toString()),
11 | double.parse(map['lng'].toString()),
12 | );
13 |
14 | /// Directions responses contain the following root elements:
15 | ///
16 | /// * `status` contains metadata on the request. See [DirectionsStatus].
17 | /// * `geocodedWaypoints` contains an array with details about the
18 | /// geocoding of origin, destination and waypoints. See
19 | /// [GeocodedWaypoint].
20 | /// * `routes` contains an array of routes from the origin to the
21 | /// destination. See [DirectionsRoute]. Routes consist of nested Legs
22 | /// and Steps.
23 | /// * `availableTravelModes` contains an array of available travel modes.
24 | /// This field is returned when a request specifies a travel mode and
25 | /// gets no results. The array contains the available travel modes in
26 | /// the countries of the given set of waypoints. This field is not
27 | /// returned if one or more of the waypoints are via: waypoints.
28 | ///
29 | /// * `errorMessages` contains more detailed information about the reasons
30 | /// behind the given status code.
31 | class DirectionsResult {
32 | const DirectionsResult({
33 | this.routes,
34 | this.geocodedWaypoints,
35 | this.status,
36 | this.errorMessage,
37 | this.availableTravelModes,
38 | });
39 |
40 | factory DirectionsResult.fromMap(Map map) =>
41 | DirectionsResult(
42 | routes: (map['routes'] as List?)
43 | ?.mapList((_) => DirectionsRoute.fromMap(_)),
44 | geocodedWaypoints:
45 | (map[''] as List?)?.mapList((_) => GeocodedWaypoint.fromMap(_)),
46 | status: map['status'] != null ? DirectionsStatus(map['status']) : null,
47 | errorMessage: map['error_message'] as String?,
48 | availableTravelModes: (map['available_travel_modes'] as List?)
49 | ?.mapList((_) => TravelMode(_)),
50 | );
51 |
52 | /// When the Directions API returns results, it places them within a
53 | /// (JSON) routes array. Even if the service returns no results (such
54 | /// as if the origin and/or destination doesn't exist) it still
55 | /// returns an empty routes array. (XML responses consist of zero or
56 | /// more elements.)
57 | ///
58 | /// Each element of the routes array contains a single result from
59 | /// the specified origin and destination. This route may consist of
60 | /// one or more legs depending on whether any waypoints were specified.
61 | /// As well, the route also contains copyright and warning information
62 | /// which must be displayed to the user in addition to the routing
63 | /// information.
64 | final List? routes;
65 |
66 | /// Details about the geocoding of every waypoint, as well as origin
67 | /// and destination, can be found in the (JSON) geocoded_waypoints
68 | /// array. These can be used to infer why the service would return
69 | /// unexpected or no routes.
70 | ///
71 | /// Elements in the geocoded_waypoints array correspond, by their
72 | /// zero-based position, to the origin, the waypoints in the order
73 | /// they are specified, and the destination.
74 | final List? geocodedWaypoints;
75 |
76 | /// The status field within the Directions response object contains
77 | /// the status of the request, and may contain debugging information
78 | /// to help you track down why the Directions service failed. The
79 | /// status field may contain the following values:
80 | /// * [DirectionsStatus.ok] indicates the response contains a valid
81 | /// result.
82 | /// * [DirectionsStatus.notFound] indicates at least one of the
83 | /// locations specified in the request's origin, destination, or
84 | /// waypoints could not be geocoded.
85 | /// * [DirectionsStatus.zeroResults] indicates no route could be
86 | /// found between the origin and destination.
87 | /// * [DirectionsStatus.maxWaypointExceeded] indicates that too
88 | /// many waypoints were provided in the request. For applications
89 | /// using the Directions API as a web service, or the [directions
90 | /// service in the Maps JavaScript API][maps_js_api], the maximum
91 | /// allowed number of waypoints is 25, plus the origin and destination.
92 | /// * [DirectionsStatus.maxRouteLengthExceeded] indicates the
93 | /// requested route is too long and cannot be processed. This error
94 | /// occurs when more complex directions are returned. Try reducing
95 | /// the number of waypoints, turns, or instructions.
96 | /// * [DirectionsStatus.invalidRequest] indicates that the provided
97 | /// request was invalid. Common causes of this status include an
98 | /// invalid parameter or parameter value.
99 | /// * [DirectionsStatus.overDailyLimit] indicates any of the following:
100 | /// * The API key is missing or invalid.
101 | /// * Billing has not been enabled on your account.
102 | /// * A self-imposed usage cap has been exceeded.
103 | /// * The provided method of payment is no longer valid (for example,
104 | /// a credit card has expired).
105 | /// * See the [Maps FAQ][faq] to learn how to fix this.
106 | /// * [DirectionsStatus.overQueryLimit] indicates the service has
107 | /// received too many requests from your application within the
108 | /// allowed time period.
109 | /// * [DirectionsStatus.requestDenied] indicates that the service
110 | /// denied use of the directions service by your application.
111 | /// * [DirectionsStatus.unknownError] indicates a directions request
112 | /// could not be processed due to a server error. The request may
113 | /// succeed if you try again.
114 | ///
115 | /// [faq]: https://developers.google.com/maps/faq#over-limit-key-error
116 | /// [maps_js_api]: https://developers.google.com/maps/documentation/javascript/directions
117 | final DirectionsStatus? status;
118 |
119 | /// When the status code is other than OK, there may be an additional
120 | /// `errorMessage` field within the Directions response object. This
121 | /// field contains more detailed information about the reasons behind
122 | /// the given status code.
123 | final String? errorMessage;
124 |
125 | /// Contains an array of available travel modes. This field is returned
126 | /// when a request specifies a travel mode and gets no results. The array
127 | /// contains the available travel modes in the countries of the given set
128 | /// of waypoints. This field is not returned if one or more of the
129 | /// waypoints are via: waypoints. See details below.
130 | final List? availableTravelModes;
131 | }
132 |
133 | /// When the Directions API returns results, it places them within a
134 | /// (JSON) routes array. Even if the service returns no results (such
135 | /// as if the origin and/or destination doesn't exist) it still
136 | /// returns an empty routes array. (XML responses consist of zero or
137 | /// more elements.)
138 | ///
139 | /// Each element of the routes array contains a single result from
140 | /// the specified origin and destination. This route may consist of
141 | /// one or more legs depending on whether any waypoints were specified.
142 | /// As well, the route also contains copyright and warning information
143 | /// which must be displayed to the user in addition to the routing
144 | /// information.
145 | ///
146 | /// Each route within the routes field may contain the following fields:
147 | ///
148 | /// * `summary` contains a short textual description for the route,
149 | /// suitable for naming and disambiguating the route from alternatives.
150 | /// * `legs` contains an array which contains information about a
151 | /// leg of the route, between two locations within the given route.
152 | /// A separate leg will be present for each waypoint or destination
153 | /// specified. (A route with no waypoints will contain exactly one
154 | /// leg within the legs array.) Each leg consists of a series of
155 | /// steps. (See [Leg].)
156 | /// * `waypointOrder` contains an array indicating the order of any
157 | /// waypoints in the calculated route. This waypoints may be reordered
158 | /// if the request was passed optimize:true within its waypoints parameter.
159 | /// * `overviewPolyline` contains a single points object that holds
160 | /// an [encoded polyline][enc_polyline] representation of the route.
161 | /// This polyline is an approximate (smoothed) path of the resulting
162 | /// directions.
163 | /// * `bounds` contains the viewport bounding box of the
164 | /// [overviewPolyline].
165 | /// * `copyrights` contains the copyrights text to be displayed for
166 | /// this route. You must handle and display this information yourself.
167 | /// * `warnings` contains an array of warnings to be displayed when
168 | /// showing these directions. You must handle and display these
169 | /// warnings yourself.
170 | /// * `fare`: If present, contains the total fare (that is, the total
171 | /// ticket costs) on this route. This property is only returned for
172 | /// transit requests and only for routes where fare information is
173 | /// available for all transit legs. The information includes:
174 | /// * `currency`: An [ISO 4217 currency code][iso4217] indicating the
175 | /// currency that the amount is expressed in.
176 | /// * `value`: The total fare amount, in the currency specified above.
177 | /// * `text`: The total fare amount, formatted in the requested language.
178 | ///
179 | /// **Note**: The Directions API only returns fare information for
180 | /// requests that contain either an API key or a client ID and digital
181 | /// signature.
182 | ///
183 | /// [enc_polyline]: https://developers.google.com/maps/documentation/utilities/polylinealgorithm
184 | /// [iso4217]: https://en.wikipedia.org/wiki/ISO_4217
185 | class DirectionsRoute {
186 | const DirectionsRoute({
187 | this.bounds,
188 | this.copyrights,
189 | this.legs,
190 | this.overviewPolyline,
191 | this.summary,
192 | this.warnings,
193 | this.waypointOrder,
194 | this.fare,
195 | });
196 |
197 | factory DirectionsRoute.fromMap(Map map) => DirectionsRoute(
198 | bounds: GeoCoordBounds(
199 | northeast: _getGeoCoordFromMap(map['bounds']['northeast'])!,
200 | southwest: _getGeoCoordFromMap(map['bounds']['southwest'])!,
201 | ),
202 | copyrights: map['copyrights'] as String?,
203 | legs: (map['legs'] as List?)?.mapList((_) => Leg.fromMap(_)),
204 | overviewPolyline: map['overview_polyline'] != null
205 | ? OverviewPolyline.fromMap(map['overview_polyline'])
206 | : null,
207 | summary: map['summary'] as String?,
208 | warnings: (map['warnings'] as List?)?.mapList((_) => _ as String?),
209 | waypointOrder: (map['waypoint_order'] as List?)
210 | ?.mapList((_) => num.tryParse(_.toString())),
211 | fare: map['fare'] != null ? Fare.fromMap(map['fare']) : null,
212 | );
213 |
214 | /// Contains the viewport bounding box of the [overviewPolyline].
215 | final GeoCoordBounds? bounds;
216 |
217 | /// Contains the copyrights text to be displayed for this route.
218 | /// You must handle and display this information yourself.
219 | final String? copyrights;
220 |
221 | /// Contains an array which contains information about a
222 | /// leg of the route, between two locations within the given route.
223 | /// A separate leg will be present for each waypoint or destination
224 | /// specified. (A route with no waypoints will contain exactly one
225 | /// leg within the legs array.) Each leg consists of a series of
226 | /// steps. (See [Leg].)
227 | final List? legs;
228 |
229 | List? get overviewPath =>
230 | overviewPolyline?.points?.isNotEmpty == true
231 | ? gpl
232 | .decodePolyline(overviewPolyline!.points!)
233 | .mapList((_) => GeoCoord._fromList(_))
234 | : null;
235 |
236 | /// Contains a single points object that holds an
237 | /// [encoded polyline][enc_polyline] representation of the route.
238 | /// This polyline is an approximate (smoothed) path of the resulting
239 | /// directions.
240 | ///
241 | /// [enc_polyline]: https://developers.google.com/maps/documentation/utilities/polylinealgorithm
242 | final OverviewPolyline? overviewPolyline;
243 |
244 | /// Contains a short textual description for the route, suitable for
245 | /// naming and disambiguating the route from alternatives.
246 | final String? summary;
247 |
248 | /// Contains an array of warnings to be displayed when showing these
249 | /// directions. You must handle and display these warnings yourself.
250 | final List? warnings;
251 |
252 | /// Contains an array indicating the order of any waypoints in the
253 | /// calculated route. This waypoints may be reordered if the request
254 | /// was passed `optimize:true` within its waypoints parameter.
255 | final List? waypointOrder;
256 |
257 | /// Contains the total fare (that is, the total
258 | /// ticket costs) on this route. This property is only returned for
259 | /// transit requests and only for routes where fare information is
260 | /// available for all transit legs. The information includes:
261 | /// * `currency`: An [ISO 4217 currency code][iso4217] indicating the
262 | /// currency that the amount is expressed in.
263 | /// * `value`: The total fare amount, in the currency specified above.
264 | /// * `text`: The total fare amount, formatted in the requested language.
265 | ///
266 | /// [iso4217]: https://en.wikipedia.org/wiki/ISO_4217
267 | final Fare? fare;
268 | }
269 |
270 | /// Details about the geocoding of every waypoint, as well as origin
271 | /// and destination, can be found in the (JSON) geocoded_waypoints
272 | /// array. These can be used to infer why the service would return
273 | /// unexpected or no routes.
274 | ///
275 | /// Elements in the geocoded_waypoints array correspond, by their
276 | /// zero-based position, to the origin, the waypoints in the order
277 | /// they are specified, and the destination. Each element includes
278 | /// the following details about the geocoding operation for the
279 | /// corresponding waypoint:
280 | ///
281 | /// [geocoderStatus] indicates the status code resulting from the
282 | /// geocoding operation. This field may contain the following values.
283 | /// * "OK" indicates that no errors occurred; the address was
284 | /// successfully parsed and at least one geocode was returned.
285 | /// * "ZERO_RESULTS" indicates that the geocode was successful
286 | /// but returned no results. This may occur if the geocoder was
287 | /// passed a non-existent address.
288 | ///
289 | /// [partialMatch] indicates that the geocoder did not return an
290 | /// exact match for the original request, though it was able to
291 | /// match part of the requested address. You may wish to examine
292 | /// the original request for misspellings and/or an incomplete
293 | /// address.
294 | ///
295 | /// Partial matches most often occur for street addresses
296 | /// that do not exist within the locality you pass in the
297 | /// request. Partial matches may also be returned when a
298 | /// request matches two or more locations in the same locality.
299 | /// For example, "21 Henr St, Bristol, UK" will return a
300 | /// partial match for both Henry Street and Henrietta Street.
301 | /// Note that if a request includes a misspelled address
302 | /// component, the geocoding service may suggest an alternative
303 | /// address. Suggestions triggered in this way will also be
304 | /// marked as a partial match.
305 | ///
306 | /// [placeId] is a unique identifier that can be used with other
307 | /// Google APIs. For example, you can use the place_id from a
308 | /// [Google Place Autocomplete response][autocomplete_response]
309 | /// to calculate directions to a local business. See the
310 | /// [Place ID overview][place_id_overview].
311 | ///
312 | /// [autocomplete_response]: https://developers.google.com/places/web-service/autocomplete#place_autocomplete_responses
313 | /// [place_id_overview]: https://developers.google.com/places/place-id
314 | ///
315 | /// [types] indicates the address type of the geocoding result
316 | /// used for calculating directions. The following types are
317 | /// returned:
318 | /// * [street_address] indicates a precise street address.
319 | /// * [route] indicates a named route (such as "US 101").
320 | /// * [intersection] indicates a major intersection, usually
321 | /// of two major roads.
322 | /// * [political] indicates a political entity. Usually, this
323 | /// type indicates a polygon of some civil administration.
324 | /// * [country] indicates the national political entity, and
325 | /// is typically the highest order type returned by the Geocoder.
326 | /// * [administrative_area_level_1] indicates a first-order
327 | /// civil entity below the country level. Within the United
328 | /// States, these administrative levels are states. Not all
329 | /// nations exhibit these administrative levels. In most cases,
330 | /// administrative_area_level_1 short names will closely match
331 | /// ISO 3166-2 subdivisions and other widely circulated lists;
332 | /// however this is not guaranteed as our geocoding results are
333 | /// based on a variety of signals and location data.
334 | /// * [administrative_area_level_2] indicates a second-order
335 | /// civil entity below the country level. Within the United
336 | /// States, these administrative levels are counties. Not all
337 | /// nations exhibit these administrative levels.
338 | /// * [administrative_area_level_3] indicates a third-order
339 | /// civil entity below the country level. This type indicates
340 | /// a minor civil division. Not all nations exhibit these
341 | /// administrative levels.
342 | /// * [administrative_area_level_4] indicates a fourth-order
343 | /// civil entity below the country level. This type indicates
344 | /// a minor civil division. Not all nations exhibit these
345 | /// administrative levels.
346 | /// * [administrative_area_level_5] indicates a fifth-order
347 | /// civil entity below the country level. This type indicates
348 | /// a minor civil division. Not all nations exhibit these
349 | /// administrative levels.
350 | /// * [colloquial_area] indicates a commonly-used alternative
351 | /// name for the entity.
352 | /// * [locality] indicates an incorporated city or town
353 | /// political entity.
354 | /// * [sublocality] indicates a first-order civil entity below
355 | /// a locality. For some locations may receive one of the
356 | /// additional types: sublocality_level_1 to sublocality_level_5.
357 | /// Each sublocality level is a civil entity. Larger numbers
358 | /// indicate a smaller geographic area.
359 | /// * [neighborhood] indicates a named neighborhood
360 | /// * [premise] indicates a named location, usually a building
361 | /// or collection of buildings with a common name
362 | /// * [subpremise] indicates a first-order entity below a named
363 | /// location, usually a singular building within a collection of
364 | /// buildings with a common name
365 | /// * [postal_code] indicates a postal code as used to address
366 | /// postal mail within the country.
367 | /// * [natural_feature] indicates a prominent natural feature.
368 | /// * [airport] indicates an airport.
369 | /// * [park] indicates a named park.
370 | /// * [point_of_interest] indicates a named point of interest.
371 | /// Typically, these "POI"s are prominent local entities that don't
372 | /// easily fit in another category, such as "Empire State Building"
373 | /// or "Eiffel Tower".
374 | ///
375 | /// An empty list of types indicates there are no known types for
376 | /// the particular address component, for example, Lieu-dit in
377 | /// France.
378 | class GeocodedWaypoint {
379 | const GeocodedWaypoint({
380 | this.geocoderStatus,
381 | this.partialMatch,
382 | this.placeId,
383 | this.types,
384 | });
385 |
386 | factory GeocodedWaypoint.fromMap(Map map) =>
387 | GeocodedWaypoint(
388 | geocoderStatus: map['geocoder_status'] as String?,
389 | partialMatch: map['partial_match'] == 'true',
390 | placeId: map['place_id'] as String?,
391 | types: (map['types'] as List?)?.mapList((_) => _ as String?),
392 | );
393 |
394 | /// Indicates the status code resulting from the geocoding
395 | /// operation. This field may contain the following values.
396 | /// * "OK" indicates that no errors occurred; the address was
397 | /// successfully parsed and at least one geocode was returned.
398 | /// * "ZERO_RESULTS" indicates that the geocode was successful
399 | /// but returned no results. This may occur if the geocoder was
400 | /// passed a non-existent address.
401 | final String? geocoderStatus;
402 |
403 | /// Indicates that the geocoder did not return an exact match
404 | /// for the original request, though it was able to match part
405 | /// of the requested address. You may wish to examine the
406 | /// original request for misspellings and/or an incomplete
407 | /// address.
408 | ///
409 | /// Partial matches most often occur for street addresses
410 | /// that do not exist within the locality you pass in the
411 | /// request. Partial matches may also be returned when a
412 | /// request matches two or more locations in the same locality.
413 | /// For example, "21 Henr St, Bristol, UK" will return a
414 | /// partial match for both Henry Street and Henrietta Street.
415 | /// Note that if a request includes a misspelled address
416 | /// component, the geocoding service may suggest an alternative
417 | /// address. Suggestions triggered in this way will also be
418 | /// marked as a partial match.
419 | final bool? partialMatch;
420 |
421 | /// Is a unique identifier that can be used with other
422 | /// Google APIs. For example, you can use the place_id from a
423 | /// [Google Place Autocomplete response][autocomplete_response]
424 | /// to calculate directions to a local business. See the
425 | /// [Place ID overview][place_id_overview].
426 | ///
427 | /// [autocomplete_response]: https://developers.google.com/places/web-service/autocomplete#place_autocomplete_responses
428 | /// [place_id_overview]: https://developers.google.com/places/place-id
429 | final String? placeId;
430 |
431 | /// Indicates the address type of the geocoding result
432 | /// used for calculating directions. The following types are
433 | /// returned:
434 | /// * [street_address] indicates a precise street address.
435 | /// * [route] indicates a named route (such as "US 101").
436 | /// * [intersection] indicates a major intersection, usually
437 | /// of two major roads.
438 | /// * [political] indicates a political entity. Usually, this
439 | /// type indicates a polygon of some civil administration.
440 | /// * [country] indicates the national political entity, and
441 | /// is typically the highest order type returned by the Geocoder.
442 | /// * [administrative_area_level_1] indicates a first-order
443 | /// civil entity below the country level. Within the United
444 | /// States, these administrative levels are states. Not all
445 | /// nations exhibit these administrative levels. In most cases,
446 | /// administrative_area_level_1 short names will closely match
447 | /// ISO 3166-2 subdivisions and other widely circulated lists;
448 | /// however this is not guaranteed as our geocoding results are
449 | /// based on a variety of signals and location data.
450 | /// * [administrative_area_level_2] indicates a second-order
451 | /// civil entity below the country level. Within the United
452 | /// States, these administrative levels are counties. Not all
453 | /// nations exhibit these administrative levels.
454 | /// * [administrative_area_level_3] indicates a third-order
455 | /// civil entity below the country level. This type indicates
456 | /// a minor civil division. Not all nations exhibit these
457 | /// administrative levels.
458 | /// * [administrative_area_level_4] indicates a fourth-order
459 | /// civil entity below the country level. This type indicates
460 | /// a minor civil division. Not all nations exhibit these
461 | /// administrative levels.
462 | /// * [administrative_area_level_5] indicates a fifth-order
463 | /// civil entity below the country level. This type indicates
464 | /// a minor civil division. Not all nations exhibit these
465 | /// administrative levels.
466 | /// * [colloquial_area] indicates a commonly-used alternative
467 | /// name for the entity.
468 | /// * [locality] indicates an incorporated city or town
469 | /// political entity.
470 | /// * [sublocality] indicates a first-order civil entity below
471 | /// a locality. For some locations may receive one of the
472 | /// additional types: sublocality_level_1 to sublocality_level_5.
473 | /// Each sublocality level is a civil entity. Larger numbers
474 | /// indicate a smaller geographic area.
475 | /// * [neighborhood] indicates a named neighborhood
476 | /// * [premise] indicates a named location, usually a building
477 | /// or collection of buildings with a common name
478 | /// * [subpremise] indicates a first-order entity below a named
479 | /// location, usually a singular building within a collection of
480 | /// buildings with a common name
481 | /// * [postal_code] indicates a postal code as used to address
482 | /// postal mail within the country.
483 | /// * [natural_feature] indicates a prominent natural feature.
484 | /// * [airport] indicates an airport.
485 | /// * [park] indicates a named park.
486 | /// * [point_of_interest] indicates a named point of interest.
487 | /// Typically, these "POI"s are prominent local entities that don't
488 | /// easily fit in another category, such as "Empire State Building"
489 | /// or "Eiffel Tower".
490 | ///
491 | /// An empty list of types indicates there are no known types for
492 | /// the particular address component, for example, Lieu-dit in
493 | /// France.
494 | final List? types;
495 | }
496 |
497 | /// Each element in the legs array specifies a single leg of the
498 | /// journey from the origin to the destination in the calculated
499 | /// route. For routes that contain no waypoints, the route will
500 | /// consist of a single "leg," but for routes that define one or
501 | /// more waypoints, the route will consist of one or more legs,
502 | /// corresponding to the specific legs of the journey.
503 | ///
504 | /// Each leg within the legs field(s) may contain the following
505 | /// fields:
506 | ///
507 | /// * `steps` contains an array of steps denoting information
508 | /// about each separate step of the leg of the journey.
509 | /// (See [Step])
510 | ///
511 | /// * `distance` indicates the total distance covered by this
512 | /// leg, as a field with the following elements:
513 | /// * `value` indicates the distance in meters
514 | /// * `text` contains a human-readable representation of the
515 | /// distance, displayed in units as used at the origin (or as
516 | /// overridden within the `units` parameter in the request).
517 | /// (For example, miles and feet will be used for any origin
518 | /// within the United States.) Note that regardless of what
519 | /// unit system is displayed as text, the `distance.value`
520 | /// field always contains a value expressed in meters.
521 | ///
522 | /// These fields may be absent if the distance is unknown.
523 | ///
524 | ///
525 | /// * `duration` indicates the total duration of this leg,
526 | /// as a field with the following elements:
527 | /// * `value` indicates the duration in seconds.
528 | /// * `text` contains a human-readable representation of the
529 | /// duration.
530 | ///
531 | /// These fields may be absent if the duration is unknown.
532 | ///
533 | ///
534 | /// * `durationInTraffic` indicates the total duration of this
535 | /// leg. This value is an estimate of the time in traffic based on
536 | /// current and historical traffic conditions. See the `trafficModel`
537 | /// request parameter for the options you can use to request that
538 | /// the returned value is optimistic, pessimistic, or a best-guess
539 | /// estimate. The duration in traffic is returned only if all of
540 | /// the following are true:
541 | ///
542 | /// * The request includes a valid API key, or a valid Google Maps
543 | /// * Platform Premium Plan client ID and signature.
544 | /// * The request does not include stopover waypoints. If the
545 | /// request includes waypoints, they must be prefixed with `via:`
546 | /// to avoid stopovers.
547 | /// * The request is specifically for driving directions—the
548 | /// `mode` parameter is set to `driving`.
549 | /// * The request includes a `departureTime` parameter.
550 | /// * Traffic conditions are available for the requested route.
551 | ///
552 | /// The `durationInTraffic` contains the following fields:
553 | /// * `value` indicates the duration in seconds.
554 | /// * `text` contains a human-readable representation of the duration.
555 | ///
556 | /// * `arrivalTime` contains the estimated time of arrival for this
557 | /// leg. This property is only returned for transit directions. The
558 | /// result is returned as a [Time] object with three properties:
559 | /// * `value` the time specified as a [DateTime] object.
560 | /// * `text` the time specified as a [String]. The time is displayed
561 | /// in the time zone of the transit stop.
562 | /// * `timeZone` contains the time zone of this station. The value
563 | /// is the name of the time zone as defined in the [IANA Time Zone
564 | /// Database][iana], e.g. `"America/New_York"`.
565 | ///
566 | /// * `departureTime` contains the estimated time of departure for
567 | /// this leg, specified as a [Time] object. The departureTime
568 | /// is only available for transit directions.
569 | ///
570 | /// * `startLocation` contains the latitude/longitude coordinates
571 | /// of the origin of this leg. Because the Directions API calculates
572 | /// directions between locations by using the nearest transportation
573 | /// option (usually a road) at the start and end points,
574 | /// `startLocation` may be different than the provided origin of this
575 | /// leg if, for example, a road is not near the origin.
576 | ///
577 | /// * `endLocation` contains the latitude/longitude coordinates of
578 | /// the given destination of this leg. Because the Directions API
579 | /// calculates directions between locations by using the nearest
580 | /// transportation option (usually a road) at the start and end points,
581 | /// `endLocation` may be different than the provided destination of
582 | /// this leg if, for example, a road is not near the destination.
583 | ///
584 | /// * `startAddress` contains the human-readable address (typically
585 | /// a street address) resulting from reverse geocoding the
586 | /// `startLocation` of this leg.
587 | ///
588 | /// * `endAddress` contains the human-readable address (typically a
589 | /// street address) from reverse geocoding the `endLocation` of
590 | /// this leg.
591 | ///
592 | /// [iana]: http://www.iana.org/time-zones
593 | class Leg {
594 | const Leg({
595 | this.arrivalTime,
596 | this.departureTime,
597 | this.distance,
598 | this.duration,
599 | this.durationInTraffic,
600 | this.endAddress,
601 | this.endLocation,
602 | this.startAddress,
603 | this.startLocation,
604 | this.steps,
605 | this.viaWaypoint,
606 | });
607 |
608 | factory Leg.fromMap(Map map) => Leg(
609 | arrivalTime: map['arrival_time'] != null
610 | ? Time.fromMap(map['arrival_time'])
611 | : null,
612 | departureTime: map['departure_time'] != null
613 | ? Time.fromMap(map['departure_time'])
614 | : null,
615 | distance:
616 | map['distance'] != null ? Distance.fromMap(map['distance']) : null,
617 | duration: map['duration'] != null
618 | ? DirectionsDuration.fromMap(map['duration'])
619 | : null,
620 | durationInTraffic: map['duration_in_traffic'] != null
621 | ? DirectionsDuration.fromMap(map['duration_in_traffic'])
622 | : null,
623 | endAddress: map['end_address'] as String?,
624 | endLocation: _getGeoCoordFromMap(map['end_location']),
625 | startAddress: map['start_address'] as String?,
626 | startLocation: _getGeoCoordFromMap(map['start_location']),
627 | steps: (map['steps'] as List?)?.mapList((_) => Step.fromMap(_)),
628 | viaWaypoint: (map['via_waypoint'] as List?)
629 | ?.mapList((_) => ViaWaypoint.fromMap(_)),
630 | );
631 |
632 | /// Contains the estimated time of arrival for this leg. This property
633 | /// is only returned for transit directions. The result is returned as
634 | /// a [Time] object with three properties:
635 | /// * `value` the time specified as a [DateTime] object.
636 | /// * `text` the time specified as a string. The time is displayed
637 | /// in the time zone of the transit stop.
638 | /// * `timeZone` contains the time zone of this station. The value
639 | /// is the name of the time zone as defined in the [IANA Time Zone
640 | /// Database][iana], e.g. `"America/New_York"`.
641 | final Time? arrivalTime;
642 |
643 | /// Contains the estimated time of departure for
644 | /// this leg, specified as a [Time] object. The departureTime
645 | /// is only available for transit directions.
646 | final Time? departureTime;
647 |
648 | /// Indicates the total distance covered by this leg, as a
649 | /// field with the following elements:
650 | /// * `value` indicates the distance in meters
651 | /// * `text` contains a human-readable representation of the
652 | /// distance, displayed in units as used at the origin (or as
653 | /// overridden within the `units` parameter in the request).
654 | /// (For example, miles and feet will be used for any origin
655 | /// within the United States.) Note that regardless of what
656 | /// unit system is displayed as text, the `distance.value`
657 | /// field always contains a value expressed in meters.
658 | ///
659 | /// These fields may be absent if the distance is unknown.
660 | final Distance? distance;
661 |
662 | /// Indicates the total duration of this leg, as a field with
663 | /// the following elements:
664 | /// * `value` indicates the duration in seconds.
665 | /// * `text` contains a human-readable representation of the
666 | /// duration.
667 | ///
668 | /// These fields may be absent if the duration is unknown.
669 | final DirectionsDuration? duration;
670 |
671 | /// Indicates the total duration of this leg. This value is an
672 | /// estimate of the time in traffic based on current and historical
673 | /// traffic conditions. See the `trafficModel` request parameter
674 | /// for the options you can use to request that the returned value
675 | /// is optimistic, pessimistic, or a best-guess estimate. The
676 | /// duration in traffic is returned only if all of the following
677 | /// are true:
678 | ///
679 | /// * The request includes a valid API key, or a valid Google Maps
680 | /// * Platform Premium Plan client ID and signature.
681 | /// * The request does not include stopover waypoints. If the
682 | /// request includes waypoints, they must be prefixed with `via:`
683 | /// to avoid stopovers.
684 | /// * The request is specifically for driving directions—the
685 | /// `mode` parameter is set to `driving`.
686 | /// * The request includes a `departureTime` parameter.
687 | /// * Traffic conditions are available for the requested route.
688 | ///
689 | /// The `durationInTraffic` contains the following fields:
690 | /// * `value` indicates the duration in seconds.
691 | /// * `text` contains a human-readable representation of the duration.
692 | final DirectionsDuration? durationInTraffic;
693 |
694 | /// Contains the human-readable address (typically a street address)
695 | /// from reverse geocoding the `endLocation` of this leg.
696 | final String? endAddress;
697 |
698 | /// Contains the latitude/longitude coordinates of the given
699 | /// destination of this leg. Because the Directions API calculates
700 | /// directions between locations by using the nearest transportation
701 | /// option (usually a road) at the start and end points,
702 | /// `endLocation` may be different than the provided destination of
703 | /// this leg if, for example, a road is not near the destination.
704 | final GeoCoord? endLocation;
705 |
706 | /// Contains the human-readable address (typically a street address)
707 | /// resulting from reverse geocoding the `startLocation` of this leg.
708 | final String? startAddress;
709 |
710 | /// Contains the latitude/longitude coordinates of the origin of this
711 | /// leg. Because the Directions API calculates directions between
712 | /// locations by using the nearest transportation option (usually a
713 | /// road) at the start and end points, `startLocation` may be
714 | /// different than the provided origin of this leg if, for example,
715 | /// a road is not near the origin.
716 | final GeoCoord? startLocation;
717 |
718 | /// contains an array of steps denoting information about each
719 | /// separate step of the leg of the journey.
720 | final List? steps;
721 |
722 | /// The locations of via waypoints along this leg.
723 | /// contains info about points through which the route was laid
724 | final List? viaWaypoint;
725 | }
726 |
727 | /// Each element in the steps array defines a single step of the
728 | /// calculated directions. A step is the most atomic unit of a
729 | /// direction's route, containing a single step describing a specific,
730 | /// single instruction on the journey. E.g. "Turn left at W. 4th St."
731 | /// The step not only describes the instruction but also contains
732 | /// distance and duration information relating to how this step
733 | /// relates to the following step. For example, a step denoted as
734 | /// "Merge onto I-80 West" may contain a duration of "37 miles" and
735 | /// "40 minutes," indicating that the next step is 37 miles/40
736 | /// minutes from this step.
737 | ///
738 | /// When using the Directions API to search for transit directions,
739 | /// the steps array will include additional transit details in the
740 | /// form of a transit_details array. If the directions include
741 | /// multiple modes of transportation, detailed directions will be
742 | /// provided for walking or driving steps in an inner steps array.
743 | /// For example, a walking step will include directions from the
744 | /// start and end locations: "Walk to Innes Ave & Fitch St". That
745 | /// step will include detailed walking directions for that route
746 | /// in the inner steps array, such as: "Head north-west", "Turn
747 | /// left onto Arelious Walker", and "Turn left onto Innes Ave".
748 | ///
749 | /// Each step within the steps field(s) may contain the following
750 | /// fields:
751 | ///
752 | /// * `instructions` contains formatted instructions for this step,
753 | /// presented as a text string. (Corresponds to instructions in
754 | /// the [Directions.Step interface][directions_step_interface].)
755 | ///
756 | /// * `distance` contains the distance covered by this step until
757 | /// the next step. (See the discussion of this field in Directions
758 | /// Legs above.) This field may be undefined if the distance is
759 | /// unknown.
760 | ///
761 | /// * `duration` contains the typical time required to perform the
762 | /// step, until the next step. (See the description in Directions
763 | /// Legs above.) This field may be undefined if the duration is
764 | /// unknown.
765 | ///
766 | /// * `startLocation` contains the location of the starting point
767 | /// of this step, as a single set of lat and lng fields.
768 | ///
769 | /// * `endLocation` contains the location of the last point of this
770 | /// step, as a single set of lat and lng fields.
771 | ///
772 | /// * `path` contains a sequence of GeoCoords describing the
773 | /// course of this step.
774 | ///
775 | /// * `steps` contains detailed directions for walking or driving
776 | /// steps in transit directions. Substeps are only available when
777 | /// travelMode is set to "transit". The inner steps array is of
778 | /// the same type as steps.
779 | ///
780 | /// * `transitDetails` contains transit specific information.
781 | /// This field is only returned with `travelMode` is set to
782 | /// "transit". See Transit Details below. (Corresponds to transit
783 | /// in the [Directions.Step interface][directions_step_interface].)
784 | ///
785 | /// * `travelMode` contains the type of travel mode used.
786 | ///
787 | /// [directions_step_interface]: https://developers.google.com/maps/documentation/javascript/reference/directions#DirectionsStep
788 | /// [enc_polyline]: https://developers.google.com/maps/documentation/utilities/polylinealgorithm
789 | class Step {
790 | const Step({
791 | this.distance,
792 | this.duration,
793 | this.endLocation,
794 | this.instructions,
795 | this.path,
796 | this.startLocation,
797 | this.steps,
798 | this.transit,
799 | this.travelMode,
800 | this.polyline,
801 | this.maneuver,
802 | });
803 |
804 | factory Step.fromMap(Map map) => Step(
805 | distance:
806 | map['distance'] != null ? Distance.fromMap(map['distance']) : null,
807 | duration: map['duration'] != null
808 | ? DirectionsDuration.fromMap(map['duration'])
809 | : null,
810 | endLocation: _getGeoCoordFromMap(map['end_location']),
811 | startLocation: _getGeoCoordFromMap(map['start_location']),
812 | instructions: map['html_instructions'] as String?,
813 | path: (map['path'] as List?)?.mapList((_) => _getGeoCoordFromMap(_)),
814 | steps: (map['steps'] as List?)?.mapList((_) => Step.fromMap(_)),
815 | transit: map['transit_details'] != null
816 | ? TransitDetails.fromMap(map['transit_details'])
817 | : null,
818 | travelMode:
819 | map['travel_mode'] != null ? TravelMode(map['travel_mode']) : null,
820 | polyline: map['polyline'] != null
821 | ? OverviewPolyline.fromMap(map['polyline'])
822 | : null,
823 | maneuver: map['maneuver'] as String?,
824 | );
825 |
826 | /// Contains the distance covered by this step until the next
827 | /// step. This field may be undefined if the distance is unknown.
828 | final Distance? distance;
829 |
830 | /// Contains the typical time required to perform the step,
831 | /// until the next step. This field may be undefined if the
832 | /// duration is unknown.
833 | final DirectionsDuration? duration;
834 |
835 | /// Contains the location of the last point of this step, as a
836 | /// single set of lat and lng fields.
837 | final GeoCoord? endLocation;
838 |
839 | /// Contains the location of the starting point of this step, as
840 | /// a single set of lat and lng fields.
841 | final GeoCoord? startLocation;
842 |
843 | /// Contains formatted instructions for this step,
844 | /// presented as a text string. (Corresponds to instructions in
845 | /// the [Directions.Step interface][directions_step_interface].)
846 | final String? instructions;
847 |
848 | /// Contains a sequence of GeoCoords describing the course of this step.
849 | @Deprecated('Use polyline parameter instead')
850 | final List? path;
851 |
852 | /// Contains detailed directions for walking or driving
853 | /// steps in transit directions. Substeps are only available when
854 | /// travelMode is set to "transit". The inner steps array is of
855 | /// the same type as steps.
856 | final List? steps;
857 |
858 | /// Contains transit specific information.
859 | /// This field is only returned with `travelMode` is set to
860 | /// "transit". See Transit Details below. (Corresponds to transit
861 | /// in the [Directions.Step interface][directions_step_interface].)
862 | final TransitDetails? transit;
863 |
864 | /// Contains the type of travel mode used.
865 | final TravelMode? travelMode;
866 |
867 | /// Contains a points describing the course of this step.
868 | final OverviewPolyline? polyline;
869 |
870 | /// Contains the action to take for the current step (turn left, merge,
871 | /// straight, etc.).
872 | final String? maneuver;
873 | }
874 |
875 | /// Transit directions return additional information that is not
876 | /// relevant for other modes of transportation. These additional
877 | /// properties are exposed through the `transit` object,
878 | /// returned as a field of an element in the `steps` array. From
879 | /// the [TransitDetails] object you can access additional
880 | /// information about the transit stop, transit line and transit
881 | /// agency.
882 | ///
883 | /// A `transit` object may contain the following fields:
884 | ///
885 | /// * `arrivalStop` and `departureStop` contains information about
886 | /// the stop/station for this part of the trip. Stop details can
887 | /// include:
888 | /// * `name` the name of the transit station/stop. eg. "Union
889 | /// Square".
890 | /// * `location` the location of the transit station/stop,
891 | /// represented as a lat and lng field.
892 | ///
893 | /// * `arrivalTime` and `departureTime` contain the arrival or
894 | /// departure times for this leg of the journey, specified as the
895 | /// following three properties:
896 | /// * `text` the time specified as a string. The time is
897 | /// displayed in the time zone of the transit stop.
898 | /// * `value` the time specified as Unix time, or seconds
899 | /// since midnight, January 1, 1970 UTC.
900 | /// * `timeZone` contains the time zone of this station.
901 | /// The value is the name of the time zone as defined in the
902 | /// [IANA Time Zone Database][iana], e.g. `"America/New_York"`.
903 | ///
904 | /// * `headsign` specifies the direction in which to travel on
905 | /// this line, as it is marked on the vehicle or at the departure
906 | /// stop. This will often be the terminus station.
907 | ///
908 | /// * `headway` specifies the expected number of seconds between
909 | /// departures from the same stop at this time. For example, with
910 | /// a headway value of 600, you would expect a ten minute wait if
911 | /// you should miss your bus.
912 | ///
913 | /// * `numStops` contains the number of stops in this step,
914 | /// counting the arrival stop, but not the departure stop.
915 | /// For example, if your directions involve leaving from Stop A,
916 | /// passing through stops B and C, and arriving at stop D,
917 | /// `numStops` will return 3.
918 | ///
919 | /// * `tripShortName` contains the text that appears in schedules
920 | /// and sign boards to identify a transit trip to passengers. The
921 | /// text should uniquely identify a trip within a service day. For
922 | /// example, "538" is the `tripShortName` of the Amtrak train that
923 | /// leaves San Jose, CA at 15:10 on weekdays to Sacramento, CA.
924 | ///
925 | /// * `line` contains information about the transit line used in this
926 | /// step, and may include the following properties:
927 | /// * `name` contains the full name of this transit line. eg.
928 | /// "7 Avenue Express".
929 | /// * `shortName` contains the short name of this transit line.
930 | /// This will normally be a line number, such as "M7" or "355".
931 | /// * `color` contains the color commonly used in signage for this
932 | /// transit line. The color will be specified as a hex string such
933 | /// as: #FF0033.
934 | /// * `agencies` is an array containing a single [TransitAgency]
935 | /// object. The DirectionsTransitAgency] object provides information
936 | /// about the operator of the line, including the following properties:
937 | /// * `name` contains the name of the transit agency.
938 | /// * `phone` contains the phone number of the transit agency.
939 | /// * `url` contains the URL for the transit agency.
940 | ///
941 | /// You must display the names and URLs of the transit agencies
942 | /// servicing the trip results.
943 | ///
944 | ///
945 | /// * `url` contains the URL for this transit line as provided by
946 | /// the transit agency.
947 | /// * `icon` contains the URL for the icon associated with this line.
948 | /// * `textColor` contains the color of text commonly used for
949 | /// signage of this line. The color will be specified as a hex string.
950 | /// * `vehicle` contains the type of vehicle used on this line.
951 | /// This may include the following properties:
952 | /// * `name` contains the name of the vehicle on this line. eg. "Subway."
953 | /// * `type` contains the type of vehicle that runs on this line.
954 | /// See the Vehicle Type documentation for a complete list of supported values.
955 | /// * `icon` contains the URL for an icon associated with this vehicle type.
956 | /// * `localIcon` contains the URL for the icon associated with this
957 | /// vehicle type, based on the local transport signage.
958 | ///
959 | /// [iana]: http://www.iana.org/time-zones
960 | class TransitDetails {
961 | const TransitDetails({
962 | this.arrivalStop,
963 | this.departureStop,
964 | this.arrivalTime,
965 | this.departureTime,
966 | this.headsign,
967 | this.headway,
968 | this.line,
969 | this.numStops,
970 | this.tripShortName,
971 | });
972 |
973 | factory TransitDetails.fromMap(Map map) => TransitDetails(
974 | arrivalStop: map['arrival_stop'] != null
975 | ? TransitStop.fromMap(map['arrival_stop'])
976 | : null,
977 | departureStop: map['departure_stop'] != null
978 | ? TransitStop.fromMap(map['departure_stop'])
979 | : null,
980 | arrivalTime: map['arrival_time'] != null
981 | ? Time.fromMap(map['arrival_time'])
982 | : null,
983 | departureTime: map['departure_time'] != null
984 | ? Time.fromMap(map['departure_time'])
985 | : null,
986 | headsign: map['headsign'] as String?,
987 | headway: map['headway'] as num?,
988 | line: map['line'] != null ? TransitLine.fromMap(map['line']) : null,
989 | numStops: map['num_stops'] as num?,
990 | tripShortName: map['trip_short_name'] as String?,
991 | );
992 |
993 | /// Contains information about the stop/station for this part of
994 | /// the trip. Stop details can include:
995 | /// * `name` the name of the transit station/stop. eg. "Union
996 | /// Square".
997 | /// * `location` the location of the transit station/stop,
998 | /// represented as a lat and lng field.
999 | final TransitStop? arrivalStop;
1000 |
1001 | /// Contains information about the stop/station for this part of
1002 | /// the trip. Stop details can include:
1003 | /// * `name` the name of the transit station/stop. eg. "Union
1004 | /// Square".
1005 | /// * `location` the location of the transit station/stop,
1006 | /// represented as a lat and lng field.
1007 | final TransitStop? departureStop;
1008 |
1009 | /// Contain the arrival times for this leg of the journey,
1010 | /// specified as the following three properties:
1011 | /// * `text` the time specified as a string. The time is
1012 | /// displayed in the time zone of the transit stop.
1013 | /// * `value` the time specified as Unix time, or seconds
1014 | /// since midnight, January 1, 1970 UTC.
1015 | /// * `timeZone` contains the time zone of this station.
1016 | /// The value is the name of the time zone as defined in the
1017 | /// [IANA Time Zone Database][iana], e.g. `"America/New_York"`.
1018 | ///
1019 | /// [iana]: http://www.iana.org/time-zones
1020 | final Time? arrivalTime;
1021 |
1022 | /// Contain the departure times for this leg of the journey,
1023 | /// specified as the following three properties:
1024 | /// * `text` the time specified as a string. The time is
1025 | /// displayed in the time zone of the transit stop.
1026 | /// * `value` the time specified as Unix time, or seconds
1027 | /// since midnight, January 1, 1970 UTC.
1028 | /// * `timeZone` contains the time zone of this station.
1029 | /// The value is the name of the time zone as defined in the
1030 | /// [IANA Time Zone Database][iana], e.g. `"America/New_York"`.
1031 | ///
1032 | /// [iana]: http://www.iana.org/time-zones
1033 | final Time? departureTime;
1034 |
1035 | /// Specifies the direction in which to travel on this line,
1036 | /// as it is marked on the vehicle or at the departure stop.
1037 | /// This will often be the terminus station.
1038 | final String? headsign;
1039 |
1040 | /// Specifies the expected number of seconds between departures
1041 | /// from the same stop at this time. For example, with a
1042 | /// headway value of 600, you would expect a ten minute wait if
1043 | /// you should miss your bus.
1044 | final num? headway;
1045 |
1046 | /// Contains information about the transit line used in this step.
1047 | final TransitLine? line;
1048 |
1049 | /// Contains the number of stops in this step, counting the
1050 | /// arrival stop, but not the departure stop. For example,
1051 | /// if your directions involve leaving from Stop A, passing
1052 | /// through stops B and C, and arriving at stop D, `numStops`
1053 | /// will return 3.
1054 | final num? numStops;
1055 |
1056 | /// Contains the text that appears in schedules and sign boards
1057 | /// to identify a transit trip to passengers. The text should
1058 | /// uniquely identify a trip within a service day. For example,
1059 | /// "538" is the `tripShortName` of the Amtrak train that leaves
1060 | /// San Jose, CA at 15:10 on weekdays to Sacramento, CA.
1061 | final String? tripShortName;
1062 | }
1063 |
1064 | /// Contains information about the transit line used in this
1065 | /// step, and may include the following properties:
1066 | /// * `name` contains the full name of this transit line. eg.
1067 | /// "7 Avenue Express".
1068 | /// * `shortName` contains the short name of this transit line.
1069 | /// This will normally be a line number, such as "M7" or "355".
1070 | /// * `color` contains the color commonly used in signage for this
1071 | /// transit line. The color will be specified as a hex string such
1072 | /// as: #FF0033.
1073 | /// * `agencies` is an array containing a single [TransitAgency]
1074 | /// object. The [TransitAgency] object provides information
1075 | /// about the operator of the line, including the following properties:
1076 | /// * `name` contains the name of the transit agency.
1077 | /// * `phone` contains the phone number of the transit agency.
1078 | /// * `url` contains the URL for the transit agency.
1079 | ///
1080 | /// You must display the names and URLs of the transit agencies
1081 | /// servicing the trip results.
1082 | ///
1083 | ///
1084 | /// * `url` contains the URL for this transit line as provided by
1085 | /// the transit agency.
1086 | /// * `icon` contains the URL for the icon associated with this line.
1087 | /// * `textColor` contains the color of text commonly used for
1088 | /// signage of this line. The color will be specified as a hex string.
1089 | /// * `vehicle` contains the type of vehicle used on this line.
1090 | /// This may include the following properties:
1091 | /// * `name` contains the name of the vehicle on this line. eg. "Subway."
1092 | /// * `type` contains the type of vehicle that runs on this line.
1093 | /// See the Vehicle Type documentation for a complete list of supported values.
1094 | /// * `icon` contains the URL for an icon associated with this vehicle type.
1095 | /// * `localIcon` contains the URL for the icon associated with this
1096 | /// vehicle type, based on the local transport signage.
1097 | class TransitLine {
1098 | const TransitLine({
1099 | this.name,
1100 | this.shortName,
1101 | this.color,
1102 | this.agencies,
1103 | this.url,
1104 | this.icon,
1105 | this.textColor,
1106 | this.vehicle,
1107 | });
1108 |
1109 | factory TransitLine.fromMap(Map map) => TransitLine(
1110 | name: map['name'] as String?,
1111 | shortName: map['short_name'] as String?,
1112 | color: map['color'] as String?,
1113 | agencies: (map['agencies'] as List?)
1114 | ?.mapList((_) => TransitAgency.fromMap(_)),
1115 | url: map['url'] as String?,
1116 | icon: map['icon'] as String?,
1117 | textColor: map['text_color'] as String?,
1118 | vehicle:
1119 | map['vehicle'] != null ? Vehicle.fromMap(map['vehicle']) : null,
1120 | );
1121 |
1122 | /// Contains the full name of this transit line. eg. "7 Avenue Express".
1123 | final String? name;
1124 |
1125 | /// Contains the short name of this transit line. This will normally be
1126 | /// a line number, such as "M7" or "355".
1127 | final String? shortName;
1128 |
1129 | /// Contains the color commonly used in signage for this transit line.
1130 | /// The color will be specified as a hex string such as: #FF0033.
1131 | final String? color;
1132 |
1133 | /// Is an array containing a single [TransitAgency] object.
1134 | /// The [TransitAgency] object provides information
1135 | /// about the operator of the line, including the following properties:
1136 | /// * `name` contains the name of the transit agency.
1137 | /// * `phone` contains the phone number of the transit agency.
1138 | /// * `url` contains the URL for the transit agency.
1139 | ///
1140 | /// You must display the names and URLs of the transit agencies
1141 | /// servicing the trip results.
1142 | final List? agencies;
1143 |
1144 | /// Contains the URL for this transit line as provided by the transit agency.
1145 | final String? url;
1146 |
1147 | /// Contains the URL for the icon associated with this line.
1148 | final String? icon;
1149 |
1150 | /// Contains the color of text commonly used for signage of this line.
1151 | /// The color will be specified as a hex string.
1152 | final String? textColor;
1153 |
1154 | /// Contains the type of vehicle used on this line.
1155 | /// This may include the following properties:
1156 | /// * `name` contains the name of the vehicle on this line. eg. "Subway."
1157 | /// * `type` contains the type of vehicle that runs on this line.
1158 | /// See the [VehicleType] documentation for a complete list of
1159 | /// supported values.
1160 | /// * `icon` contains the URL for an icon associated with this vehicle type.
1161 | /// * `localIcon` contains the URL for the icon associated with this
1162 | /// vehicle type, based on the local transport signage.
1163 | final Vehicle? vehicle;
1164 | }
1165 |
1166 | /// Contains a single points object that holds an
1167 | /// [encoded polyline][enc_polyline] representation of the route.
1168 | /// This polyline is an approximate (smoothed) path of the resulting
1169 | /// directions.
1170 | ///
1171 | /// [enc_polyline]: https://developers.google.com/maps/documentation/utilities/polylinealgorithm
1172 | class OverviewPolyline {
1173 | const OverviewPolyline({this.points});
1174 |
1175 | factory OverviewPolyline.fromMap(Map map) =>
1176 | OverviewPolyline(
1177 | points: map['points'] as String?,
1178 | );
1179 |
1180 | /// Contains [encoded polyline][enc_polyline] representation of the
1181 | /// route. This polyline is an approximate (smoothed) path of the
1182 | /// resulting directions.
1183 | ///
1184 | /// [enc_polyline]: https://developers.google.com/maps/documentation/utilities/polylinealgorithm
1185 | final String? points;
1186 | }
1187 |
1188 | /// Details about the total distance covered by this leg, with the
1189 | /// following elements:
1190 | /// * `value` indicates the distance in meters
1191 | /// * `text` contains a human-readable representation of the
1192 | /// distance, displayed in units as used at the origin (or as
1193 | /// overridden within the `units` parameter in the request).
1194 | /// (For example, miles and feet will be used for any origin
1195 | /// within the United States.) Note that regardless of what
1196 | /// unit system is displayed as text, the `distance.value`
1197 | /// field always contains a value expressed in meters.
1198 | class Distance {
1199 | const Distance({this.text, this.value});
1200 |
1201 | factory Distance.fromMap(Map map) => Distance(
1202 | text: map['text'] as String?,
1203 | value: map['value'] as num?,
1204 | );
1205 |
1206 | /// Contains a human-readable representation of the
1207 | /// distance, displayed in units as used at the origin (or as
1208 | /// overridden within the `units` parameter in the request).
1209 | /// (For example, miles and feet will be used for any origin
1210 | /// within the United States.) Note that regardless of what
1211 | /// unit system is displayed as text, the `distance.value`
1212 | /// field always contains a value expressed in meters.
1213 | final String? text;
1214 |
1215 | /// Indicates the distance in meters
1216 | final num? value;
1217 | }
1218 |
1219 | /// Details about the total duration, with the following elements:
1220 | /// * `value` indicates the duration in seconds.
1221 | /// * `text` contains a human-readable representation of the
1222 | /// duration.
1223 | class DirectionsDuration {
1224 | const DirectionsDuration({this.text, this.value});
1225 |
1226 | factory DirectionsDuration.fromMap(Map map) =>
1227 | DirectionsDuration(
1228 | text: map['text'] as String?,
1229 | value: map['value'] as num?,
1230 | );
1231 |
1232 | /// Contains a human-readable representation of the duration.
1233 | final String? text;
1234 |
1235 | /// Indicates the duration in seconds.
1236 | final num? value;
1237 | }
1238 |
1239 | /// Details about the time, with the following elements:
1240 | /// * `value` the time specified as a [DateTime] object.
1241 | /// * `text` the time specified as a [String]. The time is displayed
1242 | /// in the time zone of the transit stop.
1243 | /// * `timeZone` contains the time zone of this station. The value
1244 | /// is the name of the time zone as defined in the [IANA Time Zone
1245 | /// Database][iana], e.g. `"America/New_York"`.
1246 | ///
1247 | /// [iana]: http://www.iana.org/time-zones
1248 | class Time {
1249 | const Time({
1250 | this.text,
1251 | this.timeZone,
1252 | this.value,
1253 | });
1254 |
1255 | factory Time.fromMap(Map map) => Time(
1256 | text: map['text'] as String?,
1257 | timeZone: map['time_zone'] as String?,
1258 | value: map['value'] != null
1259 | ? DateTime.fromMillisecondsSinceEpoch(map['value'] * 1000)
1260 | : null,
1261 | );
1262 |
1263 | /// The time specified as a [String]. The time is displayed in the time
1264 | /// zone of the transit stop.
1265 | final String? text;
1266 |
1267 | /// Contains the time zone of this station. The value is the name
1268 | /// of the time zone as defined in the [IANA Time Zone Database][iana],
1269 | /// e.g. `"America/New_York"`.
1270 | ///
1271 | /// [iana]: http://www.iana.org/time-zones
1272 | final String? timeZone;
1273 |
1274 | /// The time specified as a [DateTime] object.
1275 | final DateTime? value;
1276 | }
1277 |
1278 | /// Contains the total fare (that is, the total
1279 | /// ticket costs) on this route. This property is only returned for
1280 | /// transit requests and only for routes where fare information is
1281 | /// available for all transit legs. The information includes:
1282 | /// * `currency`: An [ISO 4217 currency code][iso4217] indicating the
1283 | /// currency that the amount is expressed in.
1284 | /// * `value`: The total fare amount, in the currency specified above.
1285 | /// * `text`: The total fare amount, formatted in the requested language.
1286 | ///
1287 | /// [iso4217]: https://en.wikipedia.org/wiki/ISO_4217
1288 | class Fare {
1289 | const Fare({
1290 | this.text,
1291 | this.currency,
1292 | this.value,
1293 | });
1294 |
1295 | factory Fare.fromMap(Map map) => Fare(
1296 | text: map['text'] as String?,
1297 | currency: map['currency'] as String?,
1298 | value: map['value'] as num?,
1299 | );
1300 |
1301 | /// The total fare amount, formatted in the requested language.
1302 | final String? text;
1303 |
1304 | /// An [ISO 4217 currency code][iso4217] indicating the
1305 | /// currency that the amount is expressed in.
1306 | final String? currency;
1307 |
1308 | /// The total fare amount, in the currency specified above.
1309 | final num? value;
1310 | }
1311 |
1312 | /// Contains information about the stop/station for this part of
1313 | /// the trip. Stop details can include:
1314 | /// * `name` the name of the transit station/stop. eg. "Union
1315 | /// Square".
1316 | /// * `location` the location of the transit station/stop,
1317 | /// represented as a lat and lng field.
1318 | class TransitStop {
1319 | const TransitStop({this.name, this.location});
1320 |
1321 | factory TransitStop.fromMap(Map map) => TransitStop(
1322 | name: map['name'] as String?,
1323 | location: _getGeoCoordFromMap(map['location']),
1324 | );
1325 |
1326 | /// The name of the transit station/stop. eg. "Union Square".
1327 | final String? name;
1328 |
1329 | /// The location of the transit station/stop, represented as a
1330 | /// lat and lng field
1331 | final GeoCoord? location;
1332 | }
1333 |
1334 | /// Provides information about the operator of the line, including
1335 | /// the following properties:
1336 | /// * `name` contains the name of the transit agency.
1337 | /// * `phone` contains the phone number of the transit agency.
1338 | /// * `url` contains the URL for the transit agency.
1339 | class TransitAgency {
1340 | const TransitAgency({
1341 | this.name,
1342 | this.phone,
1343 | this.url,
1344 | });
1345 |
1346 | factory TransitAgency.fromMap(Map map) => TransitAgency(
1347 | name: map['name'] as String?,
1348 | phone: map['phone'] as String?,
1349 | url: map['url'] as String?,
1350 | );
1351 |
1352 | /// Contains the name of the transit agency.
1353 | final String? name;
1354 |
1355 | /// Contains the phone number of the transit agency.
1356 | final String? phone;
1357 |
1358 | /// Contains the URL for the transit agency.
1359 | final String? url;
1360 | }
1361 |
1362 | /// Contains the type of vehicle used on this line.
1363 | /// This may include the following properties:
1364 | /// * `name` contains the name of the vehicle on this line. eg. "Subway."
1365 | /// * `type` contains the type of vehicle that runs on this line.
1366 | /// See the [VehicleType] documentation for a complete list of
1367 | /// supported values.
1368 | /// * `icon` contains the URL for an icon associated with this vehicle type.
1369 | /// * `localIcon` contains the URL for the icon associated with this
1370 | /// vehicle type, based on the local transport signage.
1371 | class Vehicle {
1372 | const Vehicle({
1373 | this.name,
1374 | this.type,
1375 | this.icon,
1376 | this.localIcon,
1377 | });
1378 |
1379 | factory Vehicle.fromMap(Map map) => Vehicle(
1380 | name: map['name'] as String?,
1381 | type: map['type'] != null ? VehicleType(map['type']) : null,
1382 | icon: map['icon'] as String?,
1383 | localIcon: map['local_icon'] as String?,
1384 | );
1385 |
1386 | /// Contains the name of the vehicle on this line. eg. "Subway."
1387 | final String? name;
1388 |
1389 | /// Contains the type of vehicle that runs on this line.
1390 | final VehicleType? type;
1391 |
1392 | /// Contains the URL for an icon associated with this vehicle type.
1393 | final String? icon;
1394 |
1395 | /// Contains the URL for the icon associated with this
1396 | /// vehicle type, based on the local transport signage.
1397 | final String? localIcon;
1398 | }
1399 |
1400 | /// The locations of via waypoints along this leg.
1401 | /// contains info about points through which the route was laid
1402 | class ViaWaypoint {
1403 | const ViaWaypoint({
1404 | this.location,
1405 | this.stepIndex,
1406 | this.stepInterpolation,
1407 | });
1408 |
1409 | factory ViaWaypoint.fromMap(Map map) => ViaWaypoint(
1410 | location: _getGeoCoordFromMap(map['location']),
1411 | stepIndex: map['step_index'] as int?,
1412 | stepInterpolation: map['step_interpolation'] as num?,
1413 | );
1414 |
1415 | /// The location of the waypoint.
1416 | final GeoCoord? location;
1417 |
1418 | /// The index of the step containing the waypoint.
1419 | final int? stepIndex;
1420 |
1421 | /// The position of the waypoint along the step's polyline,
1422 | /// expressed as a ratio from 0 to 1.
1423 | final num? stepInterpolation;
1424 | }
1425 |
1426 | /// The status field within the Directions response object contains
1427 | /// the status of the request, and may contain debugging information
1428 | /// to help you track down why the Directions service failed.
1429 | class DirectionsStatus {
1430 | const DirectionsStatus(this._name);
1431 |
1432 | final String? _name;
1433 |
1434 | static final values = [
1435 | invalidRequest,
1436 | maxWaypointExceeded,
1437 | notFound,
1438 | ok,
1439 | overQueryLimit,
1440 | requestDenied,
1441 | unknownError,
1442 | zeroResults
1443 | ];
1444 |
1445 | /// Indicates the response contains a valid result.
1446 | static const ok = DirectionsStatus('OK');
1447 |
1448 | /// Indicates at least one of the locations specified in the
1449 | /// request's origin, destination, or waypoints could not be geocoded.
1450 | static const notFound = DirectionsStatus('NOT_FOUND');
1451 |
1452 | /// Indicates no route could be found between the origin and destination.
1453 | static const zeroResults = DirectionsStatus('ZERO_RESULTS');
1454 |
1455 | /// Indicates that too many waypoints were provided in the request.
1456 | /// For applications using the Directions API as a web service, or
1457 | /// the [directions service in the Maps JavaScript API][maps_js_api],
1458 | /// the maximum allowed number of waypoints is 25, plus the origin
1459 | /// and destination.
1460 | static const maxWaypointExceeded = DirectionsStatus('MAX_WAYPOINTS_EXCEEDED');
1461 |
1462 | /// Indicates the requested route is too long and cannot be processed.
1463 | /// This error occurs when more complex directions are returned. Try
1464 | /// reducing the number of waypoints, turns, or instructions.
1465 | static const maxRouteLengthExceeded =
1466 | DirectionsStatus('MAX_ROUTE_LENGTH_EXCEEDED');
1467 |
1468 | /// Indicates that the provided request was invalid. Common causes of
1469 | /// this status include an invalid parameter or parameter value.
1470 | static const invalidRequest = DirectionsStatus('INVALID_REQUEST');
1471 |
1472 | /// Indicates any of the following:
1473 | /// * The API key is missing or invalid.
1474 | /// * Billing has not been enabled on your account.
1475 | /// * A self-imposed usage cap has been exceeded.
1476 | /// * The provided method of payment is no longer valid (for example,
1477 | /// a credit card has expired).
1478 | /// * See the [Maps FAQ][faq] to learn how to fix this.
1479 | static const overDailyLimit = DirectionsStatus('OVER_DAILY_LIMIT');
1480 |
1481 | /// Indicates the service has received too many requests from your
1482 | /// application within the allowed time period.
1483 | static const overQueryLimit = DirectionsStatus('OVER_QUERY_LIMIT');
1484 |
1485 | /// Indicates that the service denied use of the directions service
1486 | /// by your application.
1487 | static const requestDenied = DirectionsStatus('REQUEST_DENIED');
1488 |
1489 | /// Indicates a directions request could not be processed due to a
1490 | /// server error. The request may succeed if you try again.
1491 | static const unknownError = DirectionsStatus('UNKNOWN_ERROR');
1492 |
1493 | @override
1494 | int get hashCode => _name.hashCode;
1495 |
1496 | @override
1497 | bool operator ==(dynamic other) =>
1498 | other is DirectionsStatus && _name == other._name;
1499 |
1500 | @override
1501 | String toString() => '$_name';
1502 | }
1503 |
1504 | /// Type of vehicle.
1505 | class VehicleType {
1506 | const VehicleType(this._name);
1507 |
1508 | final String? _name;
1509 |
1510 | static final values = [
1511 | bus,
1512 | cableCard,
1513 | commuterTrain,
1514 | ferry,
1515 | funicular,
1516 | gondolaLift,
1517 | heavyRail,
1518 | highSpeedTrain,
1519 | intercityBus,
1520 | longDistanceTrain,
1521 | metroRail,
1522 | monorail,
1523 | other,
1524 | rail,
1525 | shareTaxi,
1526 | subway,
1527 | tram,
1528 | trolleybus,
1529 | ];
1530 |
1531 | /// Bus.
1532 | static const bus = VehicleType('BUS');
1533 |
1534 | /// A vehicle that operates on a cable, usually on the ground.
1535 | /// Aerial cable cars may be of the type GONDOLA_LIFT.
1536 | static const cableCard = VehicleType('CABLE_CAR');
1537 |
1538 | /// Commuter rail.
1539 | static const commuterTrain = VehicleType('COMMUTER_TRAIN');
1540 |
1541 | /// Ferry.
1542 | static const ferry = VehicleType('FERRY');
1543 |
1544 | /// A vehicle that is pulled up a steep incline by a cable.
1545 | static const funicular = VehicleType('FUNICULAR');
1546 |
1547 | /// An aerial cable car.
1548 | static const gondolaLift = VehicleType('GONDOLA_LIFT');
1549 |
1550 | /// Heavy rail.
1551 | static const heavyRail = VehicleType('HEAVY_RAIL');
1552 |
1553 | /// High speed train.
1554 | static const highSpeedTrain = VehicleType('HIGH_SPEED_TRAIN');
1555 |
1556 | /// Intercity bus.
1557 | static const intercityBus = VehicleType('INTERCITY_BUS');
1558 |
1559 | /// Long distance train.
1560 | static const longDistanceTrain = VehicleType('LONG_DISTANCE_TRAIN');
1561 |
1562 | /// Light rail.
1563 | static const metroRail = VehicleType('METRO_RAIL');
1564 |
1565 | /// Monorail.
1566 | static const monorail = VehicleType('MONORAIL');
1567 |
1568 | /// Other vehicles.
1569 | static const other = VehicleType('OTHER');
1570 |
1571 | /// Rail.
1572 | static const rail = VehicleType('RAIL');
1573 |
1574 | /// Share taxi is a sort of bus transport with ability to drop
1575 | /// off and pick up passengers anywhere on its route. Generally
1576 | /// share taxi uses minibus vehicles.
1577 | static const shareTaxi = VehicleType('SHARE_TAXI');
1578 |
1579 | /// Underground light rail.
1580 | static const subway = VehicleType('SUBWAY');
1581 |
1582 | /// Above ground light rail.
1583 | static const tram = VehicleType('TRAM');
1584 |
1585 | /// Trolleybus.
1586 | static const trolleybus = VehicleType('TROLLEYBUS');
1587 |
1588 | @override
1589 | int get hashCode => _name.hashCode;
1590 |
1591 | @override
1592 | bool operator ==(dynamic other) =>
1593 | other is VehicleType && _name == other._name;
1594 |
1595 | @override
1596 | String toString() => '$_name';
1597 | }
1598 |
--------------------------------------------------------------------------------
/publish_commands.txt:
--------------------------------------------------------------------------------
1 | flutter packages pub publish --dry-run
2 | flutter packages pub publish
3 |
4 | pub uploader --package= add
--------------------------------------------------------------------------------
/pubspec.yaml:
--------------------------------------------------------------------------------
1 | name: google_directions_api
2 | version: 0.10.0
3 | homepage: https://github.com/marchdev-tk/google_directions_api
4 | description: The Directions API is a service that calculates directions between locations. You can search for directions for several modes of transportation.
5 |
6 | environment:
7 | sdk: '>=3.0.0 <4.0.0'
8 |
9 | dependencies:
10 |
11 | google_polyline_algorithm: ^3.1.0
12 | http: ^1.1.0
13 | flinq: ^2.0.2
14 |
15 | dev_dependencies:
16 | flutter_lints: ^2.0.3
17 | test: ^1.24.6
18 |
--------------------------------------------------------------------------------
/test/google_directions_api_test.dart:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021, the MarchDev Toolkit project authors. Please see the AUTHORS file
2 | // for details. All rights reserved. Use of this source code is governed by a
3 | // BSD-style license that can be found in the LICENSE file.
4 |
5 | void main() {}
6 |
--------------------------------------------------------------------------------