Skip to content

Support device orientation #714

@DestBro

Description

@DestBro

What happened?

Image

Right now the bearing value comes from:
Android -> AndroidLocation::bearing
iOS -> CLLocation::course

I tested the demo on a physical iOS device, the bearing does not look quite accurate and agile like in other maps (Google Maps, Apple Maps etc). Basically I could not get the cone rotate at all, it was always looking North.

Find the reasons why, I bet they use other sensors for this to work, like:

ChatGpt:
Magnetometer → acts like a digital compass, detecting the Earth’s magnetic field.
Accelerometer → senses gravity to know which way is “down”.
Gyroscope → tracks rotation and changes in orientation.

Affected Platforms

  • Android
  • iOS
  • Desktop (JVM)
  • Browser (JS)
  • Browser (Wasm)

Platform Version

iOS 26

Library Version

0.12.1

Sample Code

val cameraState = rememberCameraState()
val locationProvider = rememberDefaultLocationProvider()
val locationState = rememberUserLocationState(locationProvider)

LocationTrackingEffect(locationState = locationState) {
    val position = locationState.location?.position ?: return@LocationTrackingEffect
    cameraState.position = cameraState.position.copy(target = position, zoom = 17.0)
}

Box(
    modifier = Modifier.fillMaxSize(),
) {
    AnimatedVisibility(locationState.location?.position != null) {
        MaplibreMap(
            modifier = Modifier.fillMaxSize(),
            baseStyle = BaseStyle.Uri("https://mafrend.com/map/mafrend-style.json"),
            options = MapOptions(ornamentOptions = OrnamentOptions.OnlyLogo),
            cameraState = cameraState
        ) {
            Logger.withTag("debugit").i { "locationState.location?.accuracy: ${locationState.location?.accuracy}" }
            LocationPuck(
                idPrefix = "user-location",
                locationState = locationState,
                cameraState = cameraState
            )
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueWell scoped and good for newcomers

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions