Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Location puck not moving #2305

Closed
iolandarosa7 opened this issue Mar 8, 2024 · 8 comments
Closed

Location puck not moving #2305

iolandarosa7 opened this issue Mar 8, 2024 · 8 comments
Labels
bug 🪲 Something isn't working

Comments

@iolandarosa7
Copy link

Environment

  • Android OS version: Tested on Android 14, Android 12 and Android 10
  • Devices affected: Samsung phones / TCL and BlackView
  • Maps SDK Version: 11.2.0

Observed behavior and steps to reproduce

The location puck is not updating as frequent as expected.

We have a service that records user location on the background and draws the location update points on a map layer.

In version 10.16.6 of Mapbox the location puck is updated at the same time and with the same location that we receive the from the background service.

Looking at the map we can see that the location puck "follows" the same location updates that we receive from background service when the user is moving.

Now in version 11, in most cases, the puck just remains stopped in the map (both when app has connectivity or not) even knowing the user is moving and the phone is receiving location updates that are drawn on map layer.
After entering in this state the puck would only be updated to last location if we put the app on background and foreground again. And then the app keep receiving updates but the puck does not move...

Expected behavior

The puck should move when the user is moving and be up to date with the last known user location.

@iolandarosa7 iolandarosa7 added the bug 🪲 Something isn't working label Mar 8, 2024
@kiryldz
Copy link
Contributor

kiryldz commented Mar 8, 2024

@iolandarosa7 thanks for reporting! Do you see similar behaviour e.g. in v11.1.0? Trying to understand if it's regression between v10 and v11 or purely in v11.

@iolandarosa7
Copy link
Author

Yes, I observed the behavior change after updating to version 11 in the following releases: 11.0.0, 11.1.0, and 11.2.0.

This issue does not seem to occur in version 10.

Thanks.

mapbox-github-ci-writer-public-1 bot pushed a commit that referenced this issue Mar 14, 2024
* Fix artifacts when ContextMode.SHARED is used

* Fix crash on surface recreation, add test

* Handle surface resize more properly

* Fix incorrect widget position and scale when resizing the drawing surface.
@alvaroliveiravoid
Copy link

alvaroliveiravoid commented Jul 12, 2024

Hello there,

Upgraded to version 11.5.0 and we are still having the same issue.
See video as reference.

PuckMapboxCompressed.mp4

Thanks, hope to hear from you!

@jush
Copy link
Member

jush commented Jul 31, 2024

@alvaroliveiravoid could you please share how your bg service is accessing the location? We are interested in what location request you use.

Moreover, did you look at replacing the default location provider used to drive the puck (see setLocationProvider())

@jush jush added the needs info More information needed from reporter label Jul 31, 2024
@iolandarosavoid
Copy link

@jush in our service we use the DeviceLocationProvider provided by mapbox.

But we do change the request parameters though and maybe that is why the puck behaves weirdly.

Here are some parameters we set

    (...)

    private val locationService: LocationService = LocationServiceFactory.getOrCreate()

    private var locationProvider: DeviceLocationProvider? = null

    private val request = LocationProviderRequest.Builder()
        .accuracy(AccuracyLevel.HIGH)
        .interval(
            IntervalSettings.Builder()
                .minimumInterval(LocationComponentConstants.DEFAULT_FASTEST_INTERVAL_MILLIS)
                .interval(LocationComponentConstants.DEFAULT_INTERVAL_MILLIS).build(),
        )
        .build()

    (...)

    override fun onCreate() {
        super.onCreate()
        
        (...)

        val result = locationService.getDeviceLocationProvider(request)

        if (result.isValue) {
            locationProvider = result.value
        } else {
            
        }

        `locationProvider?.requestLocationUpdates(pendingIntent)`
    }

I did want to avoid to rewrite the location provider set for the puck. Seems to be a lot of code to rewrite and I am afraid that it could lead to some bugs from a custom implementation. I would like to know if there's any way we can only set the same request parameters for both?

Thanks in advance for your help

@jush jush removed the needs info More information needed from reporter label Aug 5, 2024
@jush
Copy link
Member

jush commented Aug 5, 2024

That is strange. As far as I can tell the request parameters you shared are the same than the ones in the 11.2 DefaultLocationProvider that drives the puck in the map.

One thing you could try is to attach the debugger on your app and set breakpoint to DefaultLocationProvider.kt#L163 and inspect the locations.

@iolandarosavoid
Copy link

Hi,
I think I have some information that might be helpful.

I followed your suggestion and did some debugging in DefaultLocationProvider. From what I was able to check, no error is happening and this bug only occurs in a very specific situation.

We have a feature in the app that needs to access the background location. In order to get access to the background location, we have to request the user to give the app access to the location "All the time," even when the app already has location permissions enabled to show the puck.
When we do that, the phone opens the location permission settings and puts the app in the background. After that, when we get back to the app, the puck never seems to recover and receive updates.
Even if I put the app in the background and then bring it to the foreground again, the puck updates to the latest known location but does not receive any updates for subsequent location changes.

However, if I completely close the app and then reopen it again and choose the same feature again (this time with background permissions and the app not opening location settings), the puck works just as expected and follows the location updates that I am recording.

I attached a video that shows this behavior in both cases (location updates are a bit weird in this video cause I am using GPS inside a building).

More importantly, I noticed that whenever I requested location permissions and the app went to the background, this method in DefaultLocationProvider runs:

override fun unRegisterLocationConsumer(locationConsumer: LocationConsumer) {
  locationConsumersJobs.remove(locationConsumer)?.cancel()
}

And the app seems never to recover from this. Might not be related because I am not familiar with the implementation but it was a guess from what I saw during debug.

Another information is that this feature completely works in mapbox v10, we only saw this bug happening after update to mapbox v11

mapbox-puck.mp4.zip

@iolandarosavoid
Copy link

iolandarosavoid commented Aug 27, 2024

I can confirm that this bug was fixed during the bugfix done for mapbox v 11.6.0 .
Thanks :)
I guess it can be closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants