If I'm not mistaken, Google Maps API allows you to start a Intent
that provides this navigation between the current location and a defined point, as if it were a GPS navigator.
I can not tell if he calculates the shortest distance because the documentation provides little information about it.
It's pretty simple at first, just create 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
parameter accepts addresses or a geographic 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's good to do the following check before starting to not cause the app to crash:
if (mapIntent.resolveActivity(getPackageManager() != null) {
startActivity(mapIntent);
} else {
Toast.makeText(this, "Google Maps não está disponível!", Toast.LENGTH_LONG).show();
}