open google maps to bus directions

后端 未结 2 1977
春和景丽
春和景丽 2020-12-15 11:01

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         


        
相关标签:
2条回答
  • 2020-12-15 11:33
    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.

    0 讨论(0)
  • 2020-12-15 11:34

    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.

    0 讨论(0)
提交回复
热议问题