Pergunta

I want to open Google Maps in Navigation mode from a mobile web link. This seems easy enough for iOS devices using https://developers.google.com/maps/documentation/ios/urlscheme

Is there an equivalent for Android? All I could find was this: https://developer.android.com/guide/appendix/g-app-intents.html

But that doesn't allow you to specify "transitmode" and the other parameters needed to get directions as far as I can tell.

Foi útil?

Solução

Actually, a slight modification of the methods described in the iOS Doc would work here too (I tested it before putting it here albeit, in a native app and not a web link).

The parameters necessary for this to work are pretty much the same as with the ones listed in the iOS documentation:

From the iOS Docs:

Parameters:

  • saddr: Sets the starting point for directions searches. This can be a latitude,longitude or a query formatted address. If it is a query string that returns more than one result, the first result will be selected. If the value is left blank, then the user’s current location will be used.
  • daddr: Sets the end point for directions searches. Has the same format and behavior as saddr.
  • directionsmode: Method of transportation. Can be set to: driving, transit, or walking.

They are actually, pretty much the same. They are however, no where to be found in the documents. Also, while the first 2 parameters work the usual way here, the last parameter directionsmode does not work as is. A workaround is however, listed below.

That being said, a simple URL can be constructed that can then be passed as an Uri to an Intent that will then handle the application to be launched (Google Maps if installed and/or list of browsers to choose from)

String mapURL = http://maps.google.com/maps?saddr=-33.9417, 150.9473&daddr=-33.92050, 151.04287&dirflg=d
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(mapURL));
startActivity(intent);

A few variations for the Transit Mode:

  1. &dirflg=d = for Driving directions (this is the default mode. leaving it out is the same as putting it in explicityly).
  2. &dirflg=w = for Walking directions
  3. &dirflg=r = for Public transit.
  4. &dirflg=b = for Biking directions.

That being said, at the time of running these test (I admit I was curious enough to test a little further after seeing this question ;-) ), the modes listed in the Travel Modes section don't seem work!

A little proof of sorts:

enter image description here enter image description here

Note: Credit for the initial discovery of the options

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top