cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
PaulB1
Frequent Visitor

ENABLE(Location)

I have developed an app for timesheets. In the app I collect location (Latitude and longtitude) details. The command line I use is:

 

Enable(Location);Set(_startdate,(Text( Now(),"[$-en-US]hh:mm" ))); Set(_startlat,Location.Latitude);Set(_startlong,Location.Longitude);Disable(Location)

 

This works well when a user has the location services turned on on their device (smartphone or tablet) and I receive the latitude and longtitude data into my variable.

However if a user has their location services turned off on their device I get a NULL result.

I use the enable and disable as per the powerapps guide which states "The Enable and Disable functions turn a signal on and off, respectively.". When installing the App for the first time the user is asked to use the location and camera services which they respond to "Allow". However when the user turns off their location service on the device you cannot pick up their GPS Location.

 

So my question is how to turn on Location signal when the user has the location services in the OFF position on their device? 

Any thoughts?

1 ACCEPTED SOLUTION

Accepted Solutions
Mr-Dang-MSFT
Power Apps
Power Apps

Hi @PaulB1,

I can look into this for confirmation, but my instincts tell me this is by design. As an app user, I would not want an app to get my location if I expressly told it no. 

 

My recommendation here is to check if the Location is blank. If so, Notify() the user that they should enable the location services for PowerApps to work and then restart the app. This would be done after attempting to set it to a variable.

 

Ex:

 

Enable(Location);
Set(_startdate,(Text( Now(),"[$-en-US]hh:mm" ))); 
Set(_startlat,Location.Latitude);
Set(_startlong,Location.Longitude);
Disable(Location);

If(IsBlank(_startlat),
    Notify("The location was not successfully retrieved. Be sure to enable location services and restart PowerApps.",Warning)
)

This means, "If the variable _startlat ended up being blank after attempting to get it, notify the user to enable location services and restart the app."

 

Mr. Dang

View solution in original post

3 REPLIES 3
Mr-Dang-MSFT
Power Apps
Power Apps

Hi @PaulB1,

I can look into this for confirmation, but my instincts tell me this is by design. As an app user, I would not want an app to get my location if I expressly told it no. 

 

My recommendation here is to check if the Location is blank. If so, Notify() the user that they should enable the location services for PowerApps to work and then restart the app. This would be done after attempting to set it to a variable.

 

Ex:

 

Enable(Location);
Set(_startdate,(Text( Now(),"[$-en-US]hh:mm" ))); 
Set(_startlat,Location.Latitude);
Set(_startlong,Location.Longitude);
Disable(Location);

If(IsBlank(_startlat),
    Notify("The location was not successfully retrieved. Be sure to enable location services and restart PowerApps.",Warning)
)

This means, "If the variable _startlat ended up being blank after attempting to get it, notify the user to enable location services and restart the app."

 

Mr. Dang

Thank you.

 

That was my thought process but wanted to see if there may be another option out there.

 

Cheers

Paul

Shradds
Helper I
Helper I

Hi @PaulB1 ,

 

thanks for this, i have tried using this function. However how can i  compute the location basis latitude & longitude.

 

Thanks.

 

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Power Apps Ideas

Check out the New Ideas Site

We are excited to announce a new way to share your ideas for Power Apps!

Top Solution Authors
Top Kudoed Authors
Users online (4,689)