when Btn_CheckIn.Click do
if LocationSensor1.HasLongitudeLatitude then
set Lbl_Status.Text to "جاري التحقق من الموقع..."
// حساب المسافة بين الموقع الحالي والمكتب (إحداثيات مثال: 24.7136, 46.6753)
set distance to call LocationSensor1.DistanceToPoint(24.7136, 46.6753)
if distance < 100 then // إذا كان المستخدم ضمن 100 متر
call Firebase1.StoreValue("attendance/" & Clock1.Now, "حضور: " & Clock1.Now)
set Lbl_Status.Text to "تم التسجيل بنجاح!"
else
set Lbl_Status.Text to "يجب أن تكون في المكتب لتسجيل الحضور!"
end if
else
set Lbl_Status.Text to "تفعيل GPS أولاً!"
end if
end
when Screen1.Initialize do
call Firebase1.GetValue("employees") // جلب بيانات الموظفين
end
when Firebase1.GotValue do
set Lbl_EmployeeList.Text to ""
for each item in Firebase1.Value
set Lbl_EmployeeList.Text to join(Lbl_EmployeeList.Text, "\n" & item)
end for
end
when Btn_RequestLeave.Click do
if not (Txt_LeaveReason.Text = "") then
call Firebase1.StoreValue(
"leave_requests/" & Clock1.Now,
"الموظف: " & Txt_EmployeeName.Text & "\nالسبب: " & Txt_LeaveReason.Text
)
set Lbl_Status.Text to "تم إرسال الطلب!"
else
set Lbl_Status.Text to "اكتب السبب أولاً!"
end if
end
when Firebase1.DataChanged do
if Firebase1.Tag = "leave_status" then
if Firebase1.Value = "approved" then
set Notifier1.Message to "تم قبول إجازتك!"
call Notifier1.ShowAlert
end if
end if
end
How do I arrange the blocks correctly? I've tried every step but every time there's an error and I don't know the correct order of the blocks. Thanks to everyone who can help.
If you ask an AI for a solution then at least you should be able to put some blocks together
Do the tutorials to learn the basics
Also what about revealing thr error you get?
It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.
To get an image of your blocks, right click in the Blocks Editor and select "Download Blocks as Image". You might want to use an image editor to crop etc. if required. Then post it here in the community.
A very good way to learn App Inventor is to read the free Inventor's Manual here in the AI2 free online eBook App Inventor 2 Book: Create Your Own Android Apps ... the links are at the bottom of the Web page. The book 'teaches' users how to program with AI2 blocks.
There is a free programming course here Course In A Box and the aia files for the projects in the book are here: App Inventor 2 Book: Create Your Own Android Apps
How to do a lot of basic things with App Inventor are described here: How do you...? .
I want to build an app for employees. Employees can only check in when they're at work. However, I can't figure out the order of the blocks. I know the codes, but when I apply them to the program, I don't know their order. When I click the "Check In" button, it checks the location. If it's in the same specified location, the message says "Check In." If it's not, the message says "You're out of work."
I know that the latitude and longitude of the location must be specified, but the way the application is built is what I'm facing difficulty with.
I know that each employee must specify a work location, but the initial setup is what I'm facing difficulty with.
[On CheckIn Button Click]
│
├── IF [LocationSensor.HasLocation] = TRUE:
│ │
│ ├── SET StatusLabel.Text = "Checking location..."
│ │
│ ├── CALCULATE distance using Haversine formula:
│ │ │
│ │ ├── 1. Convert office & current coordinates to radians
│ │ ├── 2. Calculate differences (Δlat, Δlng)
│ │ ├── 3. Apply formula:
│ │ │ a = sin²(Δlat/2) + cos(lat1) * cos(lat2) * sin²(Δlng/2)
│ │ │ c = 2 * atan2(√a, √(1−a))
│ │ │ distance = Earth radius (6,371km) × c
│ │ │
│ │ └── 4. Compare with allowed radius (100m)
│ │
│ ├── IF distance < 100m:
│ │ │
│ │ ├── SAVE to Firebase:
│ │ │ Path: "attendance/current_timestamp"
│ │ │ Value: "Checked in at [time]"
│ │ │
│ │ └── SET StatusLabel.Text = "Success!"
│ │
│ └── ELSE:
│ └── SET StatusLabel.Text = "You're outside the 100m range!"
│
└── ELSE:
└── SET StatusLabel.Text = "Enable GPS first!"
Sorry for the long post.
But is this what I meant?
I don't know how to install them using blocks.
Is there a picture that's close to it that I can benefit from?