Search code examples
androidgoogle-mapsandroid-studioandroid-intentdirection

Android Studio: Redirecting to the phone's Google Maps App with a start and end address pre-filled


I would like to redirect the user to the Google Maps apps on the phone through intents I assume to get the direction/route. However, I would like the user to enter in the address for both starting and destination. Using this information, I hope to open the Maps with the starting and ending point inputted. (The starting and ending address will be in string format, as opposed to Lat/long).

I did research but I am still confused on how to proceed.

Appreciate any help regarding this inquiry.

Thanks in advance.


Solution

  • Check the official documentation here. You just need to pass the geo points via an Intent. For example, to display a map of San Francisco, you can use the following code:

    Uri gmmIntentUri = Uri.parse("geo:37.7749,-122.4194");
    Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
    mapIntent.setPackage("com.google.android.apps.maps");
    if (mapIntent.resolveActivity(getPackageManager()) != null) {
        startActivity(mapIntent);
    }