-3

I'm working on a application in which i want to draw a path between current location and searched location. How can i do this ?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241

1 Answers1

0

Here is the way to draw a path.

here is the link for the library - https://github.com/ar-android/DrawRouteMaps

Add that library into your Android project.

Apply the following code inside onMapReady Method

Android Code:

    @Override
    public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    //Pass the origin coordinates(latitude,longitude)
    LatLng origin = new LatLng(-7.788969, 110.338382);

    //Pass the destination coordinates(latitude,longitude)
    LatLng destination = new LatLng(-7.781200, 110.349709);

    DrawRouteMaps.getInstance(this)
            .draw(origin, destination, mMap);
    DrawMarker.getInstance(this).draw(mMap, origin, R.drawable.marker_a, "Origin Location");
    DrawMarker.getInstance(this).draw(mMap, destination, R.drawable.marker_b, "Destination Location");

    LatLngBounds bounds = new LatLngBounds.Builder()
            .include(origin)
            .include(destination).build();
    Point displaySize = new Point();
    getWindowManager().getDefaultDisplay().getSize(displaySize);
    mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, displaySize.x, 250, 30));
}

You can also change the route color by applying this code inside colors.xml :

   <color name="colorRouteLine">YOUR COLOUR CODE</color>