Location and Geofences
Bubbl uses your device location to fetch the correct campaigns and geofences.
Step 1: Start tracking after permissions
BubblSdk.startLocationTracking(this)
Why
This enables the SDK’s background updates and geofence refresh logic.
Step 2: Manually refresh campaigns with a known location
LocationServices.getFusedLocationProviderClient(this).lastLocation
.addOnSuccessListener { location: Location? ->
if (location != null) {
BubblSdk.refreshGeofence(location.latitude, location.longitude)
} else {
BubblSdk.forceRefreshCampaigns()
}
}
Why
Manual refresh ensures geofences are loaded even before the SDK’s periodic refresh runs.
Step 3: Optional map visualizationIf you want to show geofences on a map, use BubblSdk.geofenceFlow.
lifecycleScope.launch {
BubblSdk.geofenceFlow.collectLatest { snap ->
snap ?: return@collectLatest
googleMap.clear()
snap.polygons.forEach { poly ->
googleMap.addPolygon(
PolygonOptions()
.addAll(poly.vertices)
.strokeColor(0xFF1976D2.toInt())
.fillColor(0x331976D2)
)
}
}
}
Tooltip
This is a debug visualization. You can omit map dependencies in production apps.