web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Geo location feature
Power Apps
Unanswered

Geo location feature

(0) ShareShare
ReportReport
Posted on by

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
 )
);

 

 

Categories:
I have the same question (0)
  • Verified answer
    JonDoesFlow Profile Picture
    1,304 on at

    Hey @AdaEloka 

     

    Have you checked to make sure your power app app on your phone is allowed to gain location data? 

     

    You could also add some debugging:

    // Debugging: Display current location

    Notify("Current location: " & Text(CurrentLatitude) & ", " & Text(CurrentLongitude), NotificationType.Information);

     

    Can you test on different devices?



    ---------------------------------------------------------------------------


    If I have helped you with an answer, please accept this post as a solution and thumbs up my reply. Thanks !

    Blog - JonDoesFlow
    Twitter - JonDoesFlow
    YouTube - JonDoesFlow

  • AdaEloka Profile Picture
    on at

    Hi @Jondoesflow yes the powerapp has access to location data on my phone. The debugging also didn't show any obvious issues. However, it worked well with another device. Thanks 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard