Skip to content Skip to sidebar Skip to footer

Map Intent With Multiple Points

I am trying to send an intent to Google Maps to show driving directions between multiple points. I am using the method listed here but it seems not to be working very well. The ult

Solution 1:

Use this code:

UrigmmIntentUri= Uri.parse("https://www.google.com/maps/dir/?api=1&origin=18.519513,73.868315&destination=18.518496,73.879259&waypoints=18.520561,73.872435|18.519254,73.876614|18.52152,73.877327|18.52019,73.879935&travelmode=driving");
Intentintent=newIntent(Intent.ACTION_VIEW, gmmIntentUri);
intent.setPackage("com.google.android.apps.maps");
try {
    startActivity(intent);
} catch (ActivityNotFoundException ex) {
    try {
        IntentunrestrictedIntent=newIntent(Intent.ACTION_VIEW, gmmIntentUri);
        startActivity(unrestrictedIntent);
    } catch (ActivityNotFoundException innerEx) {
        Toast.makeText(this, "Please install a maps application", Toast.LENGTH_LONG).show();
    }
}

More info in this link: https://developers.google.com/maps/documentation/urls/guide

Solution 2:

finalStringuri="http://maps.google.com/maps?daddr=Gachibowli"+"+to:Lingampally+to:Nizampet+to:kukatpally+to:moosapet+to:Nizampet+to:srnagar+to:ameerpet+to:jubileehills+to:kothaguda";
finalIntentintent=newIntent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
    startActivity(intent);
}

If you want to use lat lng modify like this:

finalStringuri="http://maps.google.com/maps?daddr=12.972442,77.580643"+"+to:12.9747,77.6094+to:12.9365,77.5447+to:12.9275,77.5906+to:12.9103,77.645";
finalIntentintent=newIntent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
if (intent.resolveActivity(MainActivity.this.getPackageManager()) != null) {
    startActivity(intent);
}

*Using "+to" you can add multiple points.

Post a Comment for "Map Intent With Multiple Points"