The Routes API. v2
Package
@googlemaps/routingConstructors
(constructor)(opts, gaxInstance)
constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback);
Construct an instance of RoutesClient.
Parameters | |
---|---|
Name | Description |
opts |
ClientOptions
|
gaxInstance |
typeof gax | typeof fallback
: loaded instance of |
Properties
apiEndpoint
get apiEndpoint(): string;
The DNS address for this API service.
apiEndpoint
static get apiEndpoint(): string;
The DNS address for this API service - same as servicePath.
auth
auth: gax.GoogleAuth;
descriptors
descriptors: Descriptors;
innerApiCalls
innerApiCalls: {
[name: string]: Function;
};
port
static get port(): number;
The port for this API service.
routesStub
routesStub?: Promise<{
[name: string]: Function;
}>;
scopes
static get scopes(): never[];
The scopes needed to make gRPC calls for every method defined in this service.
servicePath
static get servicePath(): string;
The DNS address for this API service.
universeDomain
get universeDomain(): string;
warn
warn: (code: string, message: string, warnType?: string) => void;
Methods
close()
close(): Promise<void>;
Terminate the gRPC channel and close the client.
The client will no longer be usable and all future behavior is undefined.
Returns | |
---|---|
Type | Description |
Promise<void> |
{Promise} A promise that resolves when the client is closed. |
computeRouteMatrix(request, options)
computeRouteMatrix(request?: protos.google.maps.routing.v2.IComputeRouteMatrixRequest, options?: CallOptions): gax.CancellableStream;
Takes in a list of origins and destinations and returns a stream containing route information for each combination of origin and destination.
**NOTE:** This method requires that you specify a response field mask in the input. You can provide the response field mask by using the URL parameter $fields
or fields
, or by using the HTTP/gRPC header X-Goog-FieldMask
(see the [available URL parameters and headers](https://cloud.google.com/apis/docs/system-parameters)). The value is a comma separated list of field paths. See this detailed documentation about [how to construct the field paths](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/field_mask.proto).
For example, in this method:
* Field mask of all available fields (for manual inspection): X-Goog-FieldMask: *
* Field mask of route durations, distances, element status, condition, and element indices (an example production setup): X-Goog-FieldMask: originIndex,destinationIndex,status,condition,distanceMeters,duration
It is critical that you include status
in your field mask as otherwise all messages will appear to be OK. Google discourages the use of the wildcard (*
) response field mask, because:
* Selecting only the fields that you need helps our server save computation cycles, allowing us to return the result to you with a lower latency. * Selecting only the fields that you need in your production job ensures stable latency performance. We might add more response fields in the future, and those new fields might require extra computation time. If you select all fields, or if you select all fields at the top level, then you might experience performance degradation because any new field we add will be automatically included in the response. * Selecting only the fields that you need results in a smaller response size, and thus higher network throughput.
Parameters | |
---|---|
Name | Description |
request |
IComputeRouteMatrixRequest
The request object that will be sent. |
options |
CallOptions
Call options. See CallOptions for more details. |
Returns | |
---|---|
Type | Description |
gax.CancellableStream |
{Stream} An object stream which emits on 'data' event. Please see the documentation for more details and examples. |
/**
* This snippet has been automatically generated and should be regarded as a code template only.
* It will require modifications to work.
* It may require correct/in-range values for request initialization.
* TODO(developer): Uncomment these variables before running the sample.
*/
/**
* Required. Array of origins, which determines the rows of the response
* matrix. Several size restrictions apply to the cardinality of origins and
* destinations:
* * The sum of the number of origins + the number of destinations specified
* as either `place_id` or `address` must be no greater than 50.
* * The product of number of origins × number of destinations must be no
* greater than 625 in any case.
* * The product of the number of origins × number of destinations must be no
* greater than 100 if routing_preference is set to `TRAFFIC_AWARE_OPTIMAL`.
* * The product of the number of origins × number of destinations must be no
* greater than 100 if travel_mode is set to `TRANSIT`.
*/
// const origins = [1,2,3,4]
/**
* Required. Array of destinations, which determines the columns of the
* response matrix.
*/
// const destinations = [1,2,3,4]
/**
* Optional. Specifies the mode of transportation.
*/
// const travelMode = {}
/**
* Optional. Specifies how to compute the route. The server attempts to use
* the selected routing preference to compute the route. If the routing
* preference results in an error or an extra long latency, an error is
* returned. You can specify this option only when the `travel_mode` is
* `DRIVE` or `TWO_WHEELER`, otherwise the request fails.
*/
// const routingPreference = {}
/**
* Optional. The departure time. If you don't set this value, then this value
* defaults to the time that you made the request.
* NOTE: You can only specify a `departure_time` in the past when
* `RouteTravelMode` google.maps.routing.v2.RouteTravelMode is set to
* `TRANSIT`.
*/
// const departureTime = {}
/**
* Optional. The arrival time.
* NOTE: Can only be set when
* `RouteTravelMode` google.maps.routing.v2.RouteTravelMode is set to
* `TRANSIT`. You can specify either `departure_time` or `arrival_time`, but
* not both.
*/
// const arrivalTime = {}
/**
* Optional. The BCP-47 language code, such as "en-US" or "sr-Latn". For more
* information, see Unicode Locale
* Identifier (http://www.unicode.org/reports/tr35/#Unicode_locale_identifier).
* See Language
* Support (https://developers.google.com/maps/faq#languagesupport)
* for the list of supported languages. When you don't provide this value, the
* display language is inferred from the location of the first origin.
*/
// const languageCode = 'abc123'
/**
* Optional. The region code, specified as a ccTLD ("top-level domain")
* two-character value. For more information see Country code top-level
* domains (https://en.wikipedia.org/wiki/List_of_Internet_top-level_domains#Country_code_top-level_domains).
*/
// const regionCode = 'abc123'
/**
* Optional. Specifies the units of measure for the display fields.
*/
// const units = {}
/**
* Optional. A list of extra computations which may be used to complete the
* request. Note: These extra computations may return extra fields on the
* response. These extra fields must also be specified in the field mask to be
* returned in the response.
*/
// const extraComputations = [1,2,3,4]
/**
* Optional. Specifies the assumptions to use when calculating time in
* traffic. This setting affects the value returned in the duration field in
* the RouteMatrixElement google.maps.routing.v2.RouteMatrixElement which
* contains the predicted time in traffic based on historical averages.
* RoutingPreference google.maps.routing.v2.RoutingPreference to
* `TRAFFIC_AWARE_OPTIMAL` and
* RouteTravelMode google.maps.routing.v2.RouteTravelMode to `DRIVE`.
* Defaults to `BEST_GUESS` if traffic is requested and `TrafficModel` is not
* specified.
*/
// const trafficModel = {}
/**
* Optional. Specifies preferences that influence the route returned for
* `TRANSIT` routes. NOTE: You can only specify a `transit_preferences` when
* RouteTravelMode google.maps.routing.v2.RouteTravelMode is set to
* `TRANSIT`.
*/
// const transitPreferences = {}
// Imports the Routing library
const {RoutesClient} = require('@googlemaps/routing').v2;
// Instantiates a client
const routingClient = new RoutesClient();
async function callComputeRouteMatrix() {
// Construct request
const request = {
origins,
destinations,
};
// Run request
const stream = await routingClient.computeRouteMatrix(request);
stream.on('data', (response) => { console.log(response) });
stream.on('error', (err) => { throw(err) });
stream.on('end', () => { /* API call completed */ });
}
callComputeRouteMatrix();
computeRoutes(request, options)
computeRoutes(request?: protos.google.maps.routing.v2.IComputeRoutesRequest, options?: CallOptions): Promise<[
protos.google.maps.routing.v2.IComputeRoutesResponse,
protos.google.maps.routing.v2.IComputeRoutesRequest | undefined,
{} | undefined
]>;
Returns the primary route along with optional alternate routes, given a set of terminal and intermediate waypoints.
**NOTE:** This method requires that you specify a response field mask in the input. You can provide the response field mask by using URL parameter $fields
or fields
, or by using an HTTP/gRPC header X-Goog-FieldMask
(see the [available URL parameters and headers](https://cloud.google.com/apis/docs/system-parameters)). The value is a comma separated list of field paths. See detailed documentation about [how to construct the field paths](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/field_mask.proto).
For example, in this method:
* Field mask of all available fields (for manual inspection): X-Goog-FieldMask: *
* Field mask of Route-level duration, distance, and polyline (an example production setup): X-Goog-FieldMask: routes.duration,routes.distanceMeters,routes.polyline.encodedPolyline
Google discourage the use of the wildcard (*
) response field mask, or specifying the field mask at the top level (routes
), because:
* Selecting only the fields that you need helps our server save computation cycles, allowing us to return the result to you with a lower latency. * Selecting only the fields that you need in your production job ensures stable latency performance. We might add more response fields in the future, and those new fields might require extra computation time. If you select all fields, or if you select all fields at the top level, then you might experience performance degradation because any new field we add will be automatically included in the response. * Selecting only the fields that you need results in a smaller response size, and thus higher network throughput.
Parameters | |
---|---|
Name | Description |
request |
IComputeRoutesRequest
The request object that will be sent. |
options |
CallOptions
Call options. See CallOptions for more details. |
Returns | |
---|---|
Type | Description |
Promise<[
protos.google.maps.routing.v2.IComputeRoutesResponse,
protos.google.maps.routing.v2.IComputeRoutesRequest | undefined,
{} | undefined
]> |
{Promise} - The promise which resolves to an array. The first element of the array is an object representing ComputeRoutesResponse. Please see the documentation for more details and examples. |
/**
* This snippet has been automatically generated and should be regarded as a code template only.
* It will require modifications to work.
* It may require correct/in-range values for request initialization.
* TODO(developer): Uncomment these variables before running the sample.
*/
/**
* Required. Origin waypoint.
*/
// const origin = {}
/**
* Required. Destination waypoint.
*/
// const destination = {}
/**
* Optional. A set of waypoints along the route (excluding terminal points),
* for either stopping at or passing by. Up to 25 intermediate waypoints are
* supported.
*/
// const intermediates = [1,2,3,4]
/**
* Optional. Specifies the mode of transportation.
*/
// const travelMode = {}
/**
* Optional. Specifies how to compute the route. The server
* attempts to use the selected routing preference to compute the route. If
* the routing preference results in an error or an extra long latency, then
* an error is returned. You can specify this option only when the
* `travel_mode` is `DRIVE` or `TWO_WHEELER`, otherwise the request fails.
*/
// const routingPreference = {}
/**
* Optional. Specifies your preference for the quality of the polyline.
*/
// const polylineQuality = {}
/**
* Optional. Specifies the preferred encoding for the polyline.
*/
// const polylineEncoding = {}
/**
* Optional. The departure time. If you don't set this value, then this value
* defaults to the time that you made the request.
* NOTE: You can only specify a `departure_time` in the past when
* `RouteTravelMode` google.maps.routing.v2.RouteTravelMode is set to
* `TRANSIT`. Transit trips are available for up to 7 days in the past or 100
* days in the future.
*/
// const departureTime = {}
/**
* Optional. The arrival time.
* NOTE: Can only be set when
* RouteTravelMode google.maps.routing.v2.RouteTravelMode is set to
* `TRANSIT`. You can specify either `departure_time` or `arrival_time`, but
* not both. Transit trips are available for up to 7 days in the past or 100
* days in the future.
*/
// const arrivalTime = {}
/**
* Optional. Specifies whether to calculate alternate routes in addition to
* the route. No alternative routes are returned for requests that have
* intermediate waypoints.
*/
// const computeAlternativeRoutes = true
/**
* Optional. A set of conditions to satisfy that affect the way routes are
* calculated.
*/
// const routeModifiers = {}
/**
* Optional. The BCP-47 language code, such as "en-US" or "sr-Latn". For more
* information, see Unicode Locale
* Identifier (http://www.unicode.org/reports/tr35/#Unicode_locale_identifier).
* See Language
* Support (https://developers.google.com/maps/faq#languagesupport)
* for the list of supported languages. When you don't provide this value, the
* display language is inferred from the location of the route request.
*/
// const languageCode = 'abc123'
/**
* Optional. The region code, specified as a ccTLD ("top-level domain")
* two-character value. For more information see Country code top-level
* domains (https://en.wikipedia.org/wiki/List_of_Internet_top-level_domains#Country_code_top-level_domains).
*/
// const regionCode = 'abc123'
/**
* Optional. Specifies the units of measure for the display fields. These
* fields include the `instruction` field in
* `NavigationInstruction` google.maps.routing.v2.NavigationInstruction.
* The units of measure used for the route, leg, step distance, and duration
* are not affected by this value. If you don't provide this value, then the
* display units are inferred from the location of the first origin.
*/
// const units = {}
/**
* Optional. If set to true, the service attempts to minimize the overall cost
* of the route by re-ordering the specified intermediate waypoints. The
* request fails if any of the intermediate waypoints is a `via` waypoint. Use
* `ComputeRoutesResponse.Routes.optimized_intermediate_waypoint_index` to
* find the new ordering.
* If `ComputeRoutesResponseroutes.optimized_intermediate_waypoint_index` is
* not requested in the `X-Goog-FieldMask` header, the request fails.
* If `optimize_waypoint_order` is set to false,
* `ComputeRoutesResponse.optimized_intermediate_waypoint_index` will be
* empty.
*/
// const optimizeWaypointOrder = true
/**
* Optional. Specifies what reference routes to calculate as part of the
* request in addition to the default route. A reference route is a route with
* a different route calculation objective than the default route. For example
* a `FUEL_EFFICIENT` reference route calculation takes into account various
* parameters that would generate an optimal fuel efficient route. When using
* this feature, look for
* `route_labels` google.maps.routing.v2.Route.route_labels on the
* resulting routes.
*/
// const requestedReferenceRoutes = [1,2,3,4]
/**
* Optional. A list of extra computations which may be used to complete the
* request. Note: These extra computations may return extra fields on the
* response. These extra fields must also be specified in the field mask to be
* returned in the response.
*/
// const extraComputations = [1,2,3,4]
/**
* Optional. Specifies the assumptions to use when calculating time in
* traffic. This setting affects the value returned in the duration field in
* the
* `Route` google.maps.routing.v2.Route and
* `RouteLeg` google.maps.routing.v2.RouteLeg which contains the predicted
* time in traffic based on historical averages.
* `TrafficModel` is only available for requests that have set
* `RoutingPreference` google.maps.routing.v2.RoutingPreference to
* `TRAFFIC_AWARE_OPTIMAL` and
* `RouteTravelMode` google.maps.routing.v2.RouteTravelMode to `DRIVE`.
* Defaults to `BEST_GUESS` if traffic is requested and `TrafficModel` is not
* specified.
*/
// const trafficModel = {}
/**
* Optional. Specifies preferences that influence the route returned for
* `TRANSIT` routes. NOTE: You can only specify a `transit_preferences` when
* `RouteTravelMode` google.maps.routing.v2.RouteTravelMode is set to
* `TRANSIT`.
*/
// const transitPreferences = {}
// Imports the Routing library
const {RoutesClient} = require('@googlemaps/routing').v2;
// Instantiates a client
const routingClient = new RoutesClient();
async function callComputeRoutes() {
// Construct request
const request = {
origin,
destination,
};
// Run request
const response = await routingClient.computeRoutes(request);
console.log(response);
}
callComputeRoutes();
computeRoutes(request, options, callback)
computeRoutes(request: protos.google.maps.routing.v2.IComputeRoutesRequest, options: CallOptions, callback: Callback<protos.google.maps.routing.v2.IComputeRoutesResponse, protos.google.maps.routing.v2.IComputeRoutesRequest | null | undefined, {} | null | undefined>): void;
Parameters | |
---|---|
Name | Description |
request |
IComputeRoutesRequest
|
options |
CallOptions
|
callback |
Callback<protos.google.maps.routing.v2.IComputeRoutesResponse, protos.google.maps.routing.v2.IComputeRoutesRequest | null | undefined, {} | null | undefined>
|
Returns | |
---|---|
Type | Description |
void |
computeRoutes(request, callback)
computeRoutes(request: protos.google.maps.routing.v2.IComputeRoutesRequest, callback: Callback<protos.google.maps.routing.v2.IComputeRoutesResponse, protos.google.maps.routing.v2.IComputeRoutesRequest | null | undefined, {} | null | undefined>): void;
Parameters | |
---|---|
Name | Description |
request |
IComputeRoutesRequest
|
callback |
Callback<protos.google.maps.routing.v2.IComputeRoutesResponse, protos.google.maps.routing.v2.IComputeRoutesRequest | null | undefined, {} | null | undefined>
|
Returns | |
---|---|
Type | Description |
void |
getProjectId()
getProjectId(): Promise<string>;
Returns | |
---|---|
Type | Description |
Promise<string> |
getProjectId(callback)
getProjectId(callback: Callback<string, undefined, undefined>): void;
Parameter | |
---|---|
Name | Description |
callback |
Callback<string, undefined, undefined>
|
Returns | |
---|---|
Type | Description |
void |
initialize()
initialize(): Promise<{
[name: string]: Function;
}>;
Initialize the client. Performs asynchronous operations (such as authentication) and prepares the client. This function will be called automatically when any class method is called for the first time, but if you need to initialize it before calling an actual method, feel free to call initialize() directly.
You can await on this method if you want to make sure the client is initialized.
Returns | |
---|---|
Type | Description |
Promise<{
[name: string]: Function;
}> |
{Promise} A promise that resolves to an authenticated service stub. |