Launching Google Maps Directions Via an Intent on Android

Launching Google Maps Directions via an intent on Android

You could use something like this:

Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
Uri.parse("http://maps.google.com/maps?saddr=20.344,34.34&daddr=20.5666,45.345"));
startActivity(intent);

To start the navigation from the current location, remove the saddr parameter and value.

You can use an actual street address instead of latitude and longitude. However this will give the user a dialog to choose between opening it via browser or Google Maps.

This will fire up Google Maps in navigation mode directly:

Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("google.navigation:q=an+address+city"));

UPDATE

In May 2017 Google launched the new API for universal, cross-platform Google Maps URLs:

https://developers.google.com/maps/documentation/urls/guide

You can use Intents with the new API as well.

Start google map direction intent with mode

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)

Android: open Map intent with directions with two points

have you tried this

String uri = "http://maps.google.com/maps?f=d&hl=en&saddr="+latitude1+","+longitude1+"&daddr="+latitude2+","+longitude2;
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(Intent.createChooser(intent, "Select an application"));

How to Open and Directing Google Maps using Intent?

String strUri = "http://maps.google.com/maps?q=loc:" + latitude + "," + longitude + " (" + yourLocationName + ")";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(strUri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);

open google maps through intent for specific location in android

I have not tested this but you could try :

First method:

String uri = String.format(Locale.ENGLISH, "geo:%f,%f", latitude, longitude);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
context.startActivity(intent);

EDIT:
This might not work with Google maps 7,0

hence you could change the uri to :

Second option:

String geoUri = "http://maps.google.com/maps?q=loc:" + lat + "," + lng + " (" + mTitle + ")";

where mTitle is the name of the location.

Third option:

geo:0,0?q=my+street+address

Fourth option:

String map = "http://maps.google.co.in/maps?q=" + yourAddress;

Hope that works and helps :D..

Android - How to launch Google map intent in driving mode?

This will launch google maps in Driving Mode

    Intent intent = getPackageManager().getLaunchIntentForPackage("com.google.android.apps.maps");
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse("google.navigation:/?free=1&mode=d&entry=fnls"));
startActivity(intent);

Open map to show direction from current location through intent-Android

To navigate user to destination lat long, we can use something like this

Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
Uri.parse("http://maps.google.com/maps?daddr=28.605989,77.372970"));
startActivity(intent);

Here . we are passing just destination lat long daddr=28.605989,77.372970, so by default, your current location will be source location.

To add extra information with your url .

String my_data= String.format(Locale.ENGLISH, "http://maps.google.com/maps?daddr=20.5666,45.345(My Destination Place)");

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(my_data));
intent.setPackage("com.google.android.apps.maps");
startActivity(intent);

Android - How to launch Google map intent in android app with certain location, zoom level and marker

Try the following solution:

double latitude = 40.714728;
double longitude = -73.998672;
String label = "ABC Label";
String uriBegin = "geo:" + latitude + "," + longitude;
String query = latitude + "," + longitude + "(" + label + ")";
String encodedQuery = Uri.encode(query);
String uriString = uriBegin + "?q=" + encodedQuery + "&z=16";
Uri uri = Uri.parse(uriString);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, uri);
startActivity(intent);

Credit goes here: Answer

I believe the problem had to do with the spaces in your label. Encoding the query string will eliminate the issue by replacing the spaces with valid characters



Related Topics



Leave a reply



Submit