If I’m not mistaken, the Google Maps Map API allows starting a Intent
that provides this navigation between the current location and a defined point, as if it were a GPS browser.
I can’t tell if he calculates the shortest distance, because the documentation provides little information about it.
It’s quite simple at first, just create the Intent
and start:
Uri gmmIntentUri = Uri.parse("google.navigation:q=Taronga+Zoo,+Sydney+Australia");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
The documentation makes it clear that the q
accepts addresses or a geographical position:
google.navigation:q=a+street+address
google.navigation:q=latitude,longitude
Of course you will create a dependency on Google Maps, which may not be available on the device (you will know why...)
But it is good to do the following check before starting to not cause a crash in the app:
if (mapIntent.resolveActivity(getPackageManager() != null) {
startActivity(mapIntent);
} else {
Toast.makeText(this, "Google Maps não está disponível!", Toast.LENGTH_LONG).show();
}