No_Name
No_Name

Reputation: 191

Android Compose: Coarse Location

When the user selects coarse location how do I draw the circle on the map which scales with the zoom level as well?

    val locationCallback = object : LocationCallback() {
        override fun onLocationResult(result: LocationResult) {
            super.onLocationResult(result)
            result.locations.lastOrNull()?.let { location ->
                trySend(
                    Result.Success(
                        LocationPoint(
                            latitude = location.latitude,
                            longitude = location.longitude,
                            radius = location.accuracy
                        )
                    )
                )
            }
        }
    }

I use flow to return with the location and save the accuracy for the coarse location.

I created this

GoogleMap(
    cameraPositionState = cameraPosition,
    modifier = Modifier
        .fillMaxSize()
) {
    MarkerComposable(
        userMarkerKey,
        state = userMarkerState
    ) {
        when {
            hasFineLocationPermission == true -> {
                UserFineLocationIndicator()
            }

            hasCourseLocationPermission == true -> {
                UserCoarseLocationIndicator(
                    radius = radius,
                    zoomLevel = cameraPosition.position.zoom
                )
            }
        }
    }

Which is

@Composable
fun UserCoarseLocationIndicator(
    radius: Float?,
    zoomLevel: Float
) {
    val scaledRadius = (radius ?: 12f) / (20 - zoomLevel)

    Box(
        modifier = Modifier
            .size(scaledRadius.dp)
            .clip(CircleShape)
            .background(HoaxYellow.copy(alpha = 0.3f))
    )
}

And it does not seem to work out. The zooming out does not smaller the circle. The zooming in makes the circle smaller.

How do I create the circle similalry in the Google Maps SDK?

Bonus point: Even for the accurate position, how do I draw the accurarcy circle around it?

Upvotes: 0

Views: 43

Answers (0)

Related Questions