java – How to plot a route using the maps API

Question:

I'm making an app in Android Studio for an event and I'd like to:

When opening a specific screen, the app would use the mobile gps to acquire the origin coordinates and would open the google maps app to create a route with the destination point at the event location.

thanks in advance

Answer:

Welcome!

Try this way:

 // URL para abrir o google maps
final String ulrRoute = "https://maps.google.com?saddr=Current+Location&daddr=%s,%s";

// Informe a latitude e longitude do local do evento
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse( String.format(Locale.getDefault(),ulrRoute, "-25.429138", "-49.271481") ));

// Informamos que queremos abrir a  Activity MapsActivity do com.google.android.apps.maps
i.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");

startActivity(i);
Scroll to Top