Skip to Content
API ReferenceLocationLocationMergedRepository

LocationMergedRepository

class LocationMergedRepository(locationGPSDataSource: LocationGPSDataSource, locationBeaconsSource: LocationBeaconsDataSource? = null, stepsDataSource: StepsDataSource? = null, externalScope: CoroutineScope, customSharingStarted: SharingStarted = SharingStarted.WhileSubscribed(5000), replay: Int = 0)

Merges GPS and beacon location sources to provide unified location updates.

Why this class exists: Indoor/outdoor navigation requires switching between location sources seamlessly:

  • GPS: Accurate outdoors, unreliable indoors (signal blocked by buildings)
  • Beacons: Accurate indoors, unavailable outdoors (requires Bluetooth infrastructure)

This repository intelligently combines both sources, prioritizing beacons when available (indoor) and falling back to GPS (outdoor), providing a seamless location experience.

How merging works:

  • Beacon priority: When beacons are detected, their location takes precedence (indoor accuracy)
  • GPS fallback: When beacons unavailable, uses GPS (outdoor or beacon-free areas)
  • Caching: Caches last beacon location to prevent jumps when beacons temporarily unavailable
  • Motion filtering: Optionally filters updates to only emit when user is moving (saves battery)
  • Route projection: Projects location onto route segments for accurate navigation status

When each source is used:

  • Indoor with beacons: Beacon location (high accuracy, ~1-3m)
  • Outdoor: GPS location (good accuracy, ~5-10m)
  • Indoor without beacons: GPS with building/floor context (if available)
  • Transition zones: Cached beacon location to prevent jumps

Motion detection: When StepsDataSource is provided, location updates are filtered to only emit when user movement is detected. This reduces unnecessary updates when stationary, improving battery life and reducing processing overhead.

Route projection: When a route is set via setRoute, locations are projected onto the nearest route segment. This ensures navigation status calculations use route-aligned positions, improving accuracy of “on-route” vs “off-route” detection.

Important: This class is primarily used by RoutingStatusRepository. Direct usage is typically not necessary unless implementing custom location handling.

Constructors

LocationMergedRepositoryconstructor(locationGPSDataSource: LocationGPSDataSource, locationBeaconsSource: LocationBeaconsDataSource? = null, stepsDataSource: StepsDataSource? = null, externalScope: CoroutineScope, customSharingStarted: SharingStarted = SharingStarted.WhileSubscribed(5000), replay: Int  = 0)

Properties

LOCATION_CACHED_TIME

val LOCATION_CACHED_TIME: Long

mergedLocations

val mergedLocations: SharedFlow<LzLocation?>

Types: LzLocation

Functions

setRoute

fun setRoute(route: SdkRoute?)

Types: SdkRoute

Sets the active route for location projection.

simulateBeacons

fun simulateBeacons(targetList: List<String>)

Simulates beacon detection for testing/development purposes.

Last updated on