views:

662

answers:

1

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/iphone/library/featuredarticles/iPhoneURLScheme_Reference/Articles/MapLinks.html#//apple_ref/doc/uid/TP40007894

+3  A: 

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.

So you 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.

Cannonade