Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
623 views
in Technique[技术] by (71.8m points)

iphone - open google maps to bus directions

I realise that you can open the google maps app ready for directions by doing something like this:

NSString* urlString = @"http://maps.google.com/maps?saddr=London+UK&daddr=Birmingham+UK";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: urlString]];

But is there a parameter I can add to automatically switch to bus directions? Apple's developer document doesn't seem to mention anything about it:

https://developer.apple.com/library/archive/featuredarticles/iPhoneURLScheme_Reference/MapLinks/MapLinks.html

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

From MapKiWiki:

dirflg Route type:

  • dirflg=h - Switches on "Avoid Highways" route finding mode.
  • dirflg=t - Switches on "Avoid Tolls" route finding mode.
  • dirflg=r - Switches on "Public Transit" - only works in some areas.
  • dirflg=w - Switches to walking directions - still in beta.
  • dirflg=d - Switches to driving directions.

So your URL:

NSString* urlString = @"http://maps.google.com/maps?saddr=London+UK&daddr=Birmingham+UK";

Becomes:

NSString* urlString = @"http://maps.google.com/maps?saddr=London+UK&daddr=Birmingham+UK&dirflg=r";

N.B. The data supporting public transit route types are not always available. I tried the area you used in your sample (London, Birmingham) and found it was not supported.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...