-1

For a project, I am creating an application that makes use of the Google Maps API. Currently my map displays the users current location, and when a user touches the screen, a marker is added to the map.

This is what my application looks like thus far, again it's nothing special: current state of my Android application

What I want to do is be able for a route to appear from where the user is currently located, to the destination represented by the red marker on the map. I'm not a strong programmer, and I've had a read through the Google API documentation, and it's sadly a jumble of words to me. If anyone could provide some starting points, it'd be greatly appreciated :)!

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
Aaron
  • 1
  • 1
    these "I want to" questions tend to be "too broad" to identify an answer... while it's the Directions API: https://developers.google.com/maps/documentation/directions/start – Martin Zeitler Feb 22 '19 at 08:32

1 Answers1

0

I think the most simple way to do it is getting the user current position

Application Manifest (for Android to get the current location you've to ask for permissions first)

  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
</manifest>

Activity.java

private FusedLocationProviderClient locationClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
    locationClient = LocationServices.getFusedLocationProviderClient(this);
}

and getting the latitude and longitude use the DirectionsRoute and the PolylineOptions for showing the route on the map. Check this answer I think it explains clearly how to implement it. How do I draw a route, along an existing road, between two points?