I used to be able to specify a url parameter to automatically show public transport directions, but it stopped working and now I only get driving directions when I enter a URL like this: https://www.google.com/maps/dir/120+Spring+St,+Cambridge,+MA+02141/24+Cummington+Mall,+Boston,+MA+02215/
What is the parameter I should add to get biking, walking, or public transport directions? (something like ?mode=b
)
4 Answers
Use this format:
https://www.google.com/maps/preview?saddr=[insert_from_address_here]&daddr=[insert_to_address_here]&dirflg=[insert_mode_here]
Options for dirflg
:
w
: walkingb
: bicyclingd
orh
ort
: driver
: public transit
Example: if you want to bicycle from 120 Spring St, Cambridge, MA 02141 to 24 Cummington Mall, Boston, MA 02215, your URL would be:
https://www.google.com/maps/preview?saddr=120+Spring+St,+Cambridge,+MA+02141&daddr=24+Cummington+Mall,+Boston&dirflg=b
-
Interesting. I didn't know there were two URL schemes:
maps/preview
andmaps/dir
– nachocabSep 18, 2014 at 21:22 -
3With the new Google Maps interface and URL scheme, those no longer work... I'm looking for an alternative to specify public transit on URL. Does anyone know? Jun 3, 2015 at 13:48
(Edits made 6/25/2015 based on suggestions)
I've actually been playing with the new URLs for the past several days and have posted the results of my investigations on my blog:
https://mstickles.wordpress.com/2015/06/12/gmaps-urls-intro/
There are about 11 posts covering the various parts of the URL structure, which I can't summarize well in one post. For your purposes, the Directions Options posts (Part 1 and Part 3) are probably the most relevant, along with the Data Options Reference post. I will note a couple of things, though:
The new maps URL's '/data=' section is done in a kind of "data block" setup. So, if you look at the parameter treebles mentioned for walking:
/data=!4m2!4m1!3e2
The first element, '!4m2', means this is the block (m) holding information about the map/image contents (4m) and is two elements long. The second element, '!4m1', means this is the block (m) holding directions route options (4m inside the first 4m) and is one element long. The last element, '3e2', means this is an enumerated value (e) indicating transportation mode (3e inside 4m inside 4m), with a value of 2 = walking. As treebles noted, the other possible values are 0 = driving, 1 = bicycling, 3 = transit, and 4 = flight.
The reason this is important, is that if you were to add another option that goes in those blocks, the first elements would have to change to reflect that they're "containing" more elements. So, if you wanted to specify that distances should be shown in kilometers, you would add an element '4e0' (distance units is a 4e inside 4m inside 4m; value 0 = kilometers), and the new parameter set would be:
/data=!4m3!4m2!3e2!4e0
If I wanted to specify public transit routes with a preference for taking the bus and a preference for fewer transfers, the parameter set would be:
/data=!4m5!4m4!2m2!4e2!5e0!3e3
Broken down to show which elements are in which block:
!4m5 - map/image contents block, 5 elements
- !4m4 - directions block, 4 elements
- - !2m2 - route options, 2 elements
- - - !4e2 - preferred transit route, 2 = fewer transfers
- - - (1 = best time; 3 = less walking)
- - - !5e0 - preferred transit type, 0 = bus
- - - (1=subway, 2=train, 3=tram/lt rail)
- - !3e3 - transportation mode, 3 = public transit
-
1Thanks for your contribution, but an answer that has no content other than a link is vulnerable to link rot. Editing in a small bit of information you collected would help. Like this...– user79865Jun 24, 2015 at 0:32
-
I asked the same question on Google Forums and got an answer:
[by treebles]
These are the parameters to add at the end of the directions URL for the different modes of transportation
Car /data=!4m2!4m1!3e0 Bicycling /data=!4m2!4m1!3e1 Walking /data=!4m2!4m1!3e2 Public Transit /data=!4m2!4m1!3e3 Airplane /data=!4m2!4m1!3e4
Thanks again, treebles!
Thanks to LoboFX's excellent answer, I've added this as a custom search engine in Google Chrome on my computer, so I can just type pt
[destination]
into the Chrome omnibox, and it will find public transport leaving now from my Home to that destination.
- Settings > Search > Manage Search Engines
- Search engine: Public Transport
- Keyword: pt
- URL:
https://www.google.com/maps/dir/Home/%s/data=!4m2!4m1!3e3
Of course this requires being telling Google where your home is and being logged in to your Google account.
You can replace Home
with Work
, or your most common location, say 123+Main+St+Springfield
, or even here
, if, again, you share your current location with Google.