Hello everyone,
I'm trying to create a feature in my app that detects if a user is within a particular location. The code I have works perfectly on my laptop but not on my phone. On my phone, it shows according to my code that I am "not within an approved location", when I am. What could I be doing wrong? Thanks.
UpdateContext({varPicture: Camera1.Stream});
// Constants
// Radius of the Earth in kilometers
Set(
EarthRadius,
6371
);
// Conversion factor from degrees to radians
Set(
DegreesToRadians,
Pi() / 180
);
// Specify the radius (in kilometers)
Set(
varRadius,
5
);
// Load the approved locations
ClearCollect(
colApprovedLocations,
With(
{_GeoLocations: GeoLocations},
Filter(
_GeoLocations,
User().Email in Concat(
ApprovedPersonnel,
Email,
";"
)
)
)
);
// Check if the user is within the radius of any approved location
Set(
isWithinRadius,
CountRows(
Filter(
colApprovedLocations,
EarthRadius * 2 * Asin(Sqrt(0.5 - Cos((Location.Latitude - Latitude) * DegreesToRadians) / 2 + Cos(Latitude * DegreesToRadians) * Cos(Location.Latitude * DegreesToRadians) * (1 - Cos((Location.Longitude - Longitude) * DegreesToRadians)) / 2)) <= varRadius
)
) > 0
);
// Use the isWithinRadius variable to determine if the user is in an approved location
If(
isWithinRadius,
Notify(
"Welcome back! You are within an approved location.",
NotificationType.Success
);
Navigate(HomeScreen),
Notify(
"You are not within an approved location.",
NotificationType.Error
)
);