Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I pass multiple travel modes when using The Google Maps Distance Matrix API

I need to calculating times and distances with multple travel modes, I try to pass multiple travel modes separated with | like this:

https://maps.googleapis.com/maps/api/distancematrix/json?origins=E149AQ&destinations=UB83PH|NW14SA|WC1E7HU|N78DB&mode=walking|bicycling|driving&language=en-GB&key=myKey

But it doesn't work as I expected.

like image 575
FAN Li Avatar asked Oct 31 '15 09:10

FAN Li


People also ask

How does distance matrix API work?

The Distance Matrix API provides travel distance and time for a matrix of origins and destinations, and consists of rows containing duration and distance values for each pair. Distance Matrix is available in several forms: as a standalone API. as part of the client-side Maps JavaScript API.

Can I use Google distance matrix API for free?

Google writes the following under Usage Limits: Users of the free API: 100 elements per query. 100 elements per 10 seconds. 2,500 elements per 24 hour period.

What is element in Google distance matrix API?

A request to the Distance Matrix API or the Maps JavaScript API's Distance Matrix Service that uses traffic information and/or location modifiers. Each query sent to the Distance Matrix API generates elements, where the number of origins times the number of destinations equals the number of elements.


1 Answers

Only a single travel mode is supported per request. To get results for multiple travel modes, make multiple requests.

The documentation implies that but doesn't state it explicitly:

Optional parameters

mode (defaults to driving) — Specifies the mode of transport to use when calculating distance. Valid values and other request details are specified in the Travel Modes section of this document.

Travel Modes

For the calculation of distances, you may specify the transportation mode to use. By default, distances are calculated for driving directions. The following travel modes are supported:

  • driving (default) indicates distance calculation using the road network.

  • walking requests distance calculation for walking via pedestrian paths & sidewalks (where available).

  • bicycling requests distance calculation for bicycling via bicycle paths & preferred streets (where available).

  • transit requests distance calculation via public transit routes (where available). This value may only be specified if the request includes an API key or a Google Maps API for Work client ID. 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.

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.

like image 67
geocodezip Avatar answered Sep 28 '22 04:09

geocodezip