9

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

Cœur
  • 37,241
  • 25
  • 195
  • 267
rustyshelf
  • 44,963
  • 37
  • 98
  • 104

2 Answers2

23

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.

RedBlueThing
  • 42,006
  • 17
  • 96
  • 122
  • How can we see this page in XML format now? Such as the driving directions given in XML format. For example: http://maps.googleapis.com/maps/api/directions/xml?origin=111%20Davisville%20Avenue,Toronto,ON&destination=469%20King%20Street%20West,%20Toronto,%20ON&sensor=false&dirflg=r even though there is dirflg=r at the end, it still shows driving directions. – C0D3 Dec 25 '11 at 14:03
  • the link is dead :-/ – rahulserver Oct 08 '16 at 12:25
0
String url = "http://maps.google.com/maps?f=d&daddr="+latitude+","+longitude+"&dirflg=r";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(url)); 
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);   

dirflg=r is for public transport.

Namita
  • 49
  • 9
Sharanjeet Kaur
  • 796
  • 13
  • 18