Google Maps Services API Client for Dart

Overview

google_maps_services_dart (EXPERIMENTAL)

API Specification for Google Maps Platform

This Dart package is automatically generated by the OpenAPI Generator project:

  • API version: 1.17.1
  • Build package: org.openapitools.codegen.languages.DartDioNextClientCodegen

Requirements

  • Dart 2.12.0 or later OR Flutter 1.26.0 or later
  • Dio 4.0.0+

Installation & Usage

pub.dev

To use the package from pub.dev, please include the following in pubspec.yaml

dependencies:
  google_maps_services_dart: 1.0.0

Github

If this Dart package is published to Github, please include the following in pubspec.yaml

dependencies:
  google_maps_services_dart:
    git:
      url: https://github.com/tuyen-vuduc/google-maps-services-dart.git
      #ref: main

Local development

To use the package from your local drive, please include the following in pubspec.yaml

dependencies:
  google_maps_services_dart:
    path: /path/to/google_maps_services_dart

Getting Started

Please follow the installation procedure and then run the following:

import 'package:google_maps_services_dart/google_maps_services_dart.dart';


final api = GooglesMapsServicesDart().getDirectionsAPIApi();
final String destination = Victoria, BC; // String | The place ID, address, or textual latitude/longitude value to which you wish to calculate directions. The options for the destination parameter are the same as for the origin parameter.
final String origin = Vancouver, BC; // String | The place ID, address, or textual latitude/longitude value from which you wish to calculate directions. * Place IDs must be prefixed with `place_id:`. You can retrieve place IDs from the Geocoding API and the Places API (including Place Autocomplete). For an example using place IDs from Place Autocomplete, see [Place Autocomplete and Directions](https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-directions). For more about place IDs, see the [Place ID overview](https://developers.google.com/maps/documentation/places/web-service/place-id).      ```   origin=place_id:ChIJ3S-JXmauEmsRUcIaWtf4MzE   ```    * If you pass an address, the Directions service geocodes the string and converts it to a latitude/longitude coordinate to calculate directions. This coordinate may be different from that returned by the Geocoding API, for example a building entrance rather than its center.      ```   origin=24+Sussex+Drive+Ottawa+ON   ```      Using place IDs is preferred over using addresses or latitude/longitude coordinates. Using coordinates will always result in the point being snapped to the road nearest to those coordinates - which may not be an access point to the property, or even a road that will quickly or safely lead to the destination. * If you pass coordinates, the point will snap to the nearest road. Passing a place ID is preferred. If you do pass coordinates, ensure that no space exists between the latitude and longitude values.      ```   origin=41.43206,-81.38992   ```  * Plus codes must be formatted as a global code or a compound code. Format plus codes as shown here (plus signs are url-escaped to `%2B` and spaces are url-escaped to `%20`).       * **Global code** is a 4 character area code and 6 character or longer local code (849VCWC8+R9 is `849VCWC8%2BR9`).    * **Compound code** is a 6 character or longer local code with an explicit location (CWC8+R9 Mountain View, CA, USA is `CWC8%2BR9%20Mountain%20View%20CA%20USA`).  <div class=\"note\">Note: For efficiency and accuracy, use place ID's when possible. These ID's are uniquely explicit like a lat/lng value pair and provide geocoding benefits for routing such as access points and traffic variables. Unlike an address, ID's do not require the service to perform a search or an intermediate request for place details; therefore, performance is better.</div> 
final num arrivalTime = 8.14; // num | Specifies the desired time of arrival for transit directions, in seconds since midnight, January 1, 1970 UTC. You can specify either `departure_time` or `arrival_time`, but not both. Note that `arrival_time` must be specified as an integer. 
final num departureTime = 8.14; // num | Specifies the desired time of departure. You can specify the time as an integer in seconds since midnight, January 1, 1970 UTC. If a `departure_time` later than 9999-12-31T23:59:59.999999999Z is specified, the API will fall back the `departure_time` to 9999-12-31T23:59:59.999999999Z. Alternatively, you can specify a value of now, which sets the departure time to the current time (correct to the nearest second). The departure time may be specified in two cases: * For requests where the travel mode is transit: You can optionally specify one of `departure_time` or `arrival_time`. If neither time is specified, the `departure_time` defaults to now (that is, the departure time defaults to the current time). * For requests where the travel mode is driving: You can specify the `departure_time` to receive a route and trip duration (response field: duration_in_traffic) that take traffic conditions into account. The `departure_time` must be set to the current time or some time in the future. It cannot be in the past.  <div class=\"note\">Note: If departure time is not specified, choice of route and duration are based on road network and average time-independent traffic conditions. Results for a given request may vary over time due to changes in the road network, updated average traffic conditions, and the distributed nature of the service. Results may also vary between nearly-equivalent routes at any time or frequency.</div> <div class=\"note\">Note: Distance Matrix requests specifying `departure_time` when `mode=driving` are limited to a maximum of 100 elements per request. The number of origins times the number of destinations defines the number of elements.</div> 
final bool alternatives = true; // bool | If set to `true`, specifies that the Directions service may provide more than one route alternative in the response. Note that providing route alternatives may increase the response time from the server. This is only available for requests without intermediate waypoints. For more information, see the [guide to waypoints](https://developers.google.com/maps/documentation/directions/get-directions#Waypoints). 
final String avoid = highways; // String | Indicates that the calculated route(s) should avoid the indicated features. This parameter supports the following arguments: * `tolls` indicates that the calculated route should avoid toll roads/bridges. * `highways` indicates that the calculated route should avoid highways. * `ferries` indicates that the calculated route should avoid ferries. * `indoor` indicates that the calculated route should avoid indoor steps for walking and transit directions.  It's possible to request a route that avoids any combination of tolls, highways and ferries by passing multiple restrictions to the avoid parameter. For example:   ``` avoid=tolls|highways|ferries. ``` 
final String units = metric; // String | Specifies the unit system to use when displaying results.  Directions results contain text within distance fields that may be displayed to the user to indicate the distance of a particular \"step\" of the route. By default, this text uses the unit system of the origin's country or region.  For example, a route from \"Chicago, IL\" to \"Toronto, ONT\" will display results in miles, while the reverse route will display results in kilometers. You may override this unit system by setting one explicitly within the request's units parameter, passing one of the following values:  * `metric` specifies usage of the metric system. Textual distances are returned using kilometers and meters. * `imperial` specifies usage of the Imperial (English) system. Textual distances are returned using miles and feet.  <div class=\"note\">Note: this unit system setting only affects the text displayed within distance fields. The distance fields also contain values which are always expressed in meters.</div> 
final String waypoints = MA|Lexington,MA; // String | <div class=\"caution\">Caution: Requests using more than 10 waypoints (between 11 and 25), or waypoint optimization, are billed at a higher rate. <a href=\"https://developers.google.com/maps/billing/gmp-billing#directions-advanced\">Learn more about billing</a> for Google Maps Platform products.</div>  Specifies an array of intermediate locations to include along the route between the origin and destination points as pass through or stopover locations. Waypoints alter a route by directing it through the specified location(s). The API supports waypoints for these travel modes: driving, walking and bicycling; not transit.   You can supply one or more locations separated by the pipe character (`|` or `%7C`), in the form of a place ID, an address, or latitude/longitude coordinates. By default, the Directions service calculates a route using the waypoints in the order they are given. The precedence for parsing the value of the waypoint is place ID, latitude/longitude coordinates, then address. * If you pass a place ID, you must prefix it with `place_id:`. You can retrieve place IDs from the Geocoding API and the Places API (including Place Autocomplete). For an example using place IDs from Place Autocomplete, see [Place Autocomplete and Directions](/maps/documentation/javascript/examples/places-autocomplete-directions). For more about place IDs, see the [Place ID overview](/maps/documentation/places/web-service/place-id).   <div class=\"note\">For efficiency and accuracy, use place ID's when possible. These ID's are uniquely explicit like a lat/lng value pair and provide geocoding benefits for routing such as access points and traffic variables. Unlike an address, ID's do not require the service to perform a search or an intermediate request for place details; therefore, performance is better.</div> * If you pass latitude/longitude coordinates, the values go directly to the front-end server to calculate directions without geocoding. The points are snapped to roads and might not provide the accuracy your app needs. Use coordinates when you are confident the values truly specify the points your app needs for routing without regard to possible access points or additional geocoding details. Ensure that a comma (`%2C`) and not a space (`%20`) separates the latitude and longitude values. * If you pass an address, the Directions service will geocode the string and convert it into latitude/longitude coordinates to calculate directions. If the address value is ambiguous, the value might evoke a search to disambiguate from similar addresses. For example, \"1st Street\" could be a complete value or a partial value for \"1st street NE\" or \"1st St SE\". This result may be different from that returned by the Geocoding API. You can avoid possible misinterpretations using place IDs. * Alternatively, you can supply an encoded set of points using the [Encoded Polyline Algorithm](https://developers.google.com/maps/documentation/utilities/polylinealgorithm). You will find an encoded set is useful for a large number of waypoints, because the URL is significantly shorter. All web services have a URL limit of 8192 characters.   * Encoded polylines must be prefixed with `enc:` and followed by a colon (`:`). For example: `waypoints=enc:gfo}EtohhU:`.   * You can also include multiple encoded polylines, separated by the pipe character (`|`). For example, `waypoints=via:enc:wc~oAwquwMdlTxiKtqLyiK:|enc:c~vnAamswMvlTor@tjGi}L:| via:enc:udymA{~bxM:`  ##### Influence routes with stopover and pass through points  For each waypoint in the request, the directions response appends an entry to the `legs` array to provide the details for stopovers on that leg of the journey.  If you'd like to influence the route using waypoints without adding a stopover, add the prefix `via:` to the waypoint. Waypoints prefixed with `via:` will not add an entry to the `legs` array, but will route the journey through the waypoint.  The following URL modifies the previous request such that the journey is routed through Lexington without stopping:  ``` https://maps.googleapis.com/maps/api/directions/json? origin=Boston,MA&destination=Concord,MA &waypoints=Charlestown,MA|via:Lexington,MA   ```  The `via:` prefix is most effective when creating routes in response to the user dragging the waypoints on the map. Doing so allows the user to see how the final route may look in real-time and helps ensure that waypoints are placed in locations that are accessible to the Directions API.  <div class=\"caution\">Caution: Using the `via:` prefix to avoid stopovers results in directions that are strict in their interpretation of the waypoint. This interpretation may result in severe detours on the route or `ZERO_RESULTS` in the response status code if the Directions API is unable to create directions through that point.</div>   ##### Optimize your waypoints  By default, the Directions service calculates a route through the provided waypoints in their given order. Optionally, you may pass `optimize:true` as the first argument within the waypoints parameter to allow the Directions service to optimize the provided route by rearranging the waypoints in a more efficient order. (This optimization is an application of the traveling salesperson problem.) Travel time is the primary factor which is optimized, but other factors such as distance, number of turns and many more may be taken into account when deciding which route is the most efficient. All waypoints must be stopovers for the Directions service to optimize their route.  If you instruct the Directions service to optimize the order of its waypoints, their order will be returned in the `waypoint_order` field within the routes object. The `waypoint_order` field returns values which are zero-based.  The following example calculates a road journey from Adelaide, South Australia to each of South Australia's main wine regions using route optimization.  ``` https://maps.googleapis.com/maps/api/directions/json? origin=Adelaide,SA&destination=Adelaide,SA &waypoints=optimize:true|Barossa+Valley,SA|Clare,SA|Connawarra,SA|McLaren+Vale,SA ```  Inspection of the calculated route will indicate that calculation uses waypoints in the following waypoint order:  ``` \"waypoint_order\": [ 3, 2, 0, 1 ] ```  <div class=\"caution\">Caution: Requests using waypoint optimization are billed at a higher rate. <a href=\"https://developers.devsite.corp.google.com/maps/billing/gmp-billing#directions-advanced\">Learn more about how Google Maps Platform products are billed.</a></div> 
final String language = language_example; // String | The language in which to return results.  * See the [list of supported languages](https://developers.google.com/maps/faq#languagesupport). Google often updates the supported languages, so this list may not be exhaustive. * If `language` is not supplied, the API attempts to use the preferred language as specified in the `Accept-Language` header. * The API does its best to provide a street address that is readable for both the user and locals. To achieve that goal, it returns street addresses in the local language, transliterated to a script readable by the user if necessary, observing the preferred language. All other addresses are returned in the preferred language. Address components are all returned in the same language, which is chosen from the first component. * If a name is not available in the preferred language, the API uses the closest match. * The preferred language has a small influence on the set of results that the API chooses to return, and the order in which they are returned. The geocoder interprets abbreviations differently depending on language, such as the abbreviations for street types, or synonyms that may be valid in one language but not in another. For example, _utca_ and _tér_ are synonyms for street in Hungarian.
final TravelMode mode = ; // TravelMode | For the calculation of distances and directions, you may specify the transportation mode to use. By default, `DRIVING` mode is used. By default, directions are calculated as driving directions. The following travel modes are supported:  * `DRIVING` (default) indicates standard driving directions or distance using the road network. * `WALKING` requests walking directions or distance via pedestrian paths & sidewalks (where available). * `BICYCLING` requests bicycling directions or distance via bicycle paths & preferred streets (where available). * `TRANSIT` requests directions or distance via public transit routes (where available). If you set the mode to transit, you can optionally specify either a `departure_time` or an `arrival_time`. If neither time is specified, the `departure_time` defaults to now (that is, the departure time defaults to the current time). You can also optionally include a `transit_mode` and/or a `transit_routing_preference`.  <div class=\"note\">Note: Both walking and bicycling directions may sometimes not include clear pedestrian or bicycling paths, so these directions will return warnings in the returned result which you must display to the user.</div> 
final String region = region_example; // String | The region code, specified as a [ccTLD (\"top-level domain\")](https://en.wikipedia.org/wiki/List_of_Internet_top-level_domains#Country_code_top-level_domains) two-character value. Most ccTLD codes are identical to ISO 3166-1 codes, with some notable exceptions. For example, the United Kingdom's ccTLD is \"uk\" (.co.uk) while its ISO 3166-1 code is \"gb\" (technically for the entity of \"The United Kingdom of Great Britain and Northern Ireland\").
final String trafficModel = pessimistic; // String | Specifies the assumptions to use when calculating time in traffic. This setting affects the value returned in the duration_in_traffic field in the response, which contains the predicted time in traffic based on historical averages. The `traffic_model` parameter may only be specified for driving directions where the request includes a `departure_time`. The available values for this parameter are: * `best_guess` (default) indicates that the returned duration_in_traffic should be the best estimate of travel time given what is known about both historical traffic conditions and live traffic. Live traffic becomes more important the closer the `departure_time` is to now. * `pessimistic` indicates that the returned duration_in_traffic should be longer than the actual travel time on most days, though occasional days with particularly bad traffic conditions may exceed this value. * `optimistic` indicates that the returned duration_in_traffic should be shorter than the actual travel time on most days, though occasional days with particularly good traffic conditions may be faster than this value. The default value of `best_guess` will give the most useful predictions for the vast majority of use cases. It is possible the `best_guess` travel time prediction may be shorter than `optimistic`, or alternatively, longer than `pessimistic`, due to the way the `best_guess` prediction model integrates live traffic information. 
final String transitMode = train|tram|subway; // String | Specifies one or more preferred modes of transit. This parameter may only be specified for transit directions. The parameter supports the following arguments: * `bus` indicates that the calculated route should prefer travel by bus. * `subway` indicates that the calculated route should prefer travel by subway. * `train` indicates that the calculated route should prefer travel by train. * `tram` indicates that the calculated route should prefer travel by tram and light rail. * `rail` indicates that the calculated route should prefer travel by train, tram, light rail, and subway. This is equivalent to `transit_mode=train|tram|subway`. 
final String transitRoutingPreference = less_walking; // String | Specifies preferences for transit routes. Using this parameter, you can bias the options returned, rather than accepting the default best route chosen by the API. This parameter may only be specified for transit directions. The parameter supports the following arguments: * `less_walking` indicates that the calculated route should prefer limited amounts of walking. * `fewer_transfers` indicates that the calculated route should prefer a limited number of transfers. 

try {
    final response = await api.directions(destination, origin, arrivalTime, departureTime, alternatives, avoid, units, waypoints, language, mode, region, trafficModel, transitMode, transitRoutingPreference);
    print(response);
} catch on DioError (e) {
    print("Exception when calling DirectionsAPIApi->directions: $e\n");
}

Documentation for API Endpoints

All URIs are relative to https://www.googleapis.com

Class Method HTTP request Description
DirectionsAPIApi directions GET /maps/api/directions/json
DistanceMatrixAPIApi distanceMatrix GET /maps/api/distancematrix/json
ElevationAPIApi elevation GET /maps/api/elevation/json
GeocodingAPIApi geocode GET /maps/api/geocode/json
GeolocationAPIApi geolocate POST /geolocation/v1/geolocate
PlacesAPIApi autocomplete GET /maps/api/place/autocomplete/json
PlacesAPIApi findPlaceFromText GET /maps/api/place/findplacefromtext/json
PlacesAPIApi nearbySearch GET /maps/api/place/nearbysearch/json
PlacesAPIApi placeDetails GET /maps/api/place/details/json
PlacesAPIApi placePhoto GET /maps/api/place/photo
PlacesAPIApi queryAutocomplete GET /maps/api/place/queryautocomplete/json
PlacesAPIApi textSearch GET /maps/api/place/textsearch/json
RoadsAPIApi nearestRoads GET /v1/nearestRoads
RoadsAPIApi snapToRoads GET /v1/snapToRoads
StreetViewAPIApi streetView GET /maps/api/streetview
StreetViewAPIApi streetViewMetadata GET /maps/api/streetview/metadata
TimeZoneAPIApi timezone GET /maps/api/timezone/json

Documentation For Models

Documentation For Authorization

ApiKeyAuth

  • Type: API key
  • API key parameter name: key
  • Location: URL query string

Author

You might also like...

Aplications with google maps and geolocation

Aplications with google maps and geolocation

Aplications with google maps and geolocation

Jul 26, 2022

Easy Google Maps for Flutter

Easy Google Maps for Flutter

easy_google_maps Easy Google Maps for Flutter on Web and Mobile Getting Started Mobile Follow setup for Mobile Here Web Good to go! EasyGoogleMaps(

Jul 19, 2022

Place picker on Google Maps for Flutter

Place picker on Google Maps for Flutter

Google Maps Place Picker A Flutter plugin which provides 'Picking Place' using Google Maps widget. The project relies on below packages. Map using Flu

Dec 16, 2022

Simple flutter app demonstrating usage of Google Maps

flutter_maps_example Get an API key at GoogleCloud. Enable Google Map SDK for ea

Nov 23, 2022

A Flutter plugin for integrating Google Maps in iOS, Android and Web applications

flutter_google_maps A Flutter plugin for integrating Google Maps in iOS, Android and Web applications. It is a wrapper of google_maps_flutter for Mobi

Sep 26, 2022

A flutter plugin that's decodes encoded google poly line string into list of geo-coordinates suitable for showing route/polyline on maps

A flutter plugin that's decodes encoded google poly line string into list of geo-coordinates suitable for showing route/polyline on maps

flutter_polyline_points A flutter plugin that decodes encoded google polyline string into list of geo-coordinates suitable for showing route/polyline

Oct 25, 2022

Flutter Google Maps My Track

Flutter Google Maps My Track

mytracker We invite you to subscribe to the Alpha flutter code channel on Youtub

Oct 31, 2022

A Flutter plugin which provides 'Picking Place' using Google Maps widget

A Flutter plugin which provides 'Picking Place' using Google Maps widget

Google Maps Places Picker Refractored This is a forked version of google_maps_place_picker package, with added custom styling and features.

Nov 13, 2022

Flutter package to enable clustering of location markers on Google Maps using widgets specific to each location.

Flutter package to enable clustering of location markers on Google Maps using widgets specific to each location.

flutter_google_maps_widget_cluster_markers This widget implements a very specific adaptation of google_maps_cluster_manager, allowing different ,marke

Jan 6, 2023
Releases(v1.7.1)
Owner
Tuyen VU
Addict programmer on Xamarin, .NET, iOS Swift, Android Kotlin, JavaScript, ReactJS/Native, Flutter.
Tuyen VU
Google Maps Services API Client for Dart

google_maps_services_dart (EXPERIMENTAL) API Specification for Google Maps Platform This Dart package is automatically generated by the OpenAPI Genera

Tuyen VU 0 Nov 1, 2021
Flutter Maps A Flutter app using Google Maps SDK & Directions API

Flutter Maps A Flutter app using Google Maps SDK & Directions API Plugins The plugins used in this project are: google_maps_flutter geolocator flutter

Salsabil Mohamed Hemada 1 Jul 15, 2022
A Flutter app using Google Maps SDK & Directions API

Flutter Maps A Flutter app using Google Maps SDK & Directions API Plugins The plugins used in this project are: google_maps_flutter geolocator flutter

Youhaan bootwala 1 Mar 18, 2022
A Flutter app using Google Maps SDK & Directions API

Flutter Maps A Flutter app using Google Maps SDK & Directions API Plugins The plugins used in this project are: google_maps_flutter geolocator flutter

Varun CN 2 Apr 19, 2022
This is a Flutter package that uses the Google Maps API to make a TextField that tries to autocomplete places as the user types, with simple smooth animations, making a nice UI and UX.

search_map_place This is a Flutter package that uses the Google Maps API to make a TextField that tries to autocomplete places as the user types, with

Lucas Bernardi 127 Oct 22, 2022
A car rental flutter application using firebase and google maps API

A car sharing & rental app using Flutter, Firebase & Google Maps APIs ?? About the App ?? hopOn is flutter based application for car sharing and renta

Shivani Singh 97 Dec 30, 2022
A Flutter app using Google Maps SDK & Directions API

Flutter Maps A Flutter app using Google Maps SDK & Directions API Plugins The plugins used in this project are: google_maps_flutter geolocator flutter

Tsenda LAB 1 Mar 28, 2022
A Flutter app using Google Maps SDK & Directions API

Flutter Maps A Flutter app using Google Maps SDK & Directions API Plugins The plugins used in this project are: google_maps_flutter geolocator flutter

Dreamfullstacker 16 Dec 31, 2022
A flutter plugin for Google Maps

IMPORTANT: This plugin is no longer under development Why? We initially built this plugin to fill an early gap in flutter. Since then, Google has made

AppTree Software, Inc 415 Dec 29, 2022
Flutter Google Maps Tutorial

Flutter Google Maps Tutorial YouTube Video Setup Get an API Key at https://cloud.google.com/maps-platform/ Enable Maps SDK for Android, Maps SDK for i

Marcus Ng 85 Nov 30, 2022