Select to view content in your preferred language

Subscribe to location chances using LocationDisplay

526
2
Jump to solution
12-04-2023 06:29 AM
padmalcom
Frequent Contributor

Hi, we want to react to location changes. We currently collect mapView.locationDisplay.location which works well but the flow is also collected when the location remains the same - and we want to catch changes. Is there a way to do that using the API? Or do we have to validate changes manually using a variable to compare the previous location state to the current?

0 Kudos
1 Solution

Accepted Solutions
ChanganShi1
Regular Contributor

You may construct a new SystemLocationDataSource to replace the default one.  In the new SystemLocationDataSource, you could specify the minimum time updating interval and distance tolerance, which will filter out the locations not changed much beyond the tolerance.

View solution in original post

2 Replies
ChanganShi1
Regular Contributor

You may construct a new SystemLocationDataSource to replace the default one.  In the new SystemLocationDataSource, you could specify the minimum time updating interval and distance tolerance, which will filter out the locations not changed much beyond the tolerance.

padmalcom
Frequent Contributor

Thank you @ChanganShi1, that is a very nice solution. Nevertheless, we found a Flow based way to avoid events when the position does not change:

mapView.locationDisplay.location.distinctUntilChangedBy {
   it?.position
}.collect { ... }
0 Kudos