I can draw a straight line between two points but I want to draw a route. how to do this? com.google.maps.android.compose

Viewed 487

I'm using the free Maps SDK for Android with https://googlemaps.github.io/android-maps-compose/index.html I wanted to draw lines between two points.but Polyline drawing straight line. Does anyone have any ideas?

my code:

            val singapore = LatLng(49.836510, 24.064096)
    val singapore2 = LatLng(49.840191, 24.043384)
    val cameraPositionState = rememberCameraPositionState {
        position = CameraPosition.fromLatLngZoom(singapore, 0f)
    }


    GoogleMap(
            modifier = Modifier.fillMaxWidth(),
            cameraPositionState = cameraPositionState

    ) {
        Polyline(points=listOf(singapore,singapore2),jointType= JointType.ROUND)

        Marker(
                position = singapore,
                title = "Compra",
                icon = bitmapDescriptorFromVector(context,R.drawable.shopping_cart_in_a_circle_svgrepo_com)

        )

        Marker(
                position = singapore2,
                title = "Compra",
                icon = bitmapDescriptorFromVector(context,R.drawable.shopping_cart_in_a_circle_svgrepo_com)

        )

    }
1 Answers

Map Compose lets you draw Polylines between a list of coordinates. If you want to draw a route between two coordinates, here is what you need:

  1. Fetch the route with the Google Directions API.
  2. Decode the overview_polyline string using android maps utils library with PolyUtil.decode method.
  3. Add this list of points to the Polyline.
Related