Muhammad Imtiaz
Muhammad Imtiaz

Reputation: 33

Start google map direction intent with mode

How to start android google map direction intent with source and destination latitude and longitude?
And also with traveling mode like bicycle, car...

Upvotes: 2

Views: 3193

Answers (2)

ravi
ravi

Reputation: 1001

By direction intent, I am assuming you mean the Turn By Turn Navigation intent. To do that you can do the following:

Uri gmmIntentUri = Uri.parse("google.navigation:q=37.7749,-122.4194&mode=b");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);

The main thing here is the Uri that is being used. The &mode=bat the end of the uri defines bicycling mode. You can also use d for driving mode (which is also the default). w is for walking.

You can use q=a+street+address format, which is demonstrated above or you can also use Latitude and Longitude there in format: q=latitude,longitude

Read more about this here: Google Maps Documentation

Upvotes: 2

usman nazir
usman nazir

Reputation: 101

Put navigation mode as dirflg.

  • d for driving.
  • b for bicycle.
  • w for walking.
  • l for two wheeler.

    val uri = Uri.parse("http://maps.google.com/maps?saddr=33.489954,73.098888 &daddr=33.499009,73.101076 &dirflg=w")
    val intent = Intent(Intent.ACTION_VIEW, uri)
    intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
    startActivity(intent)
    

Upvotes: 3

Related Questions