cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
KathrynHughes
Helper I
Helper I

Default fields based on current location

Hi,

 

I have a list of physical assets in a SP list this includes columns for latitude and longitude as well as the address for this asset. I would like for my app to recognise my current location and use this to then pull the information from the SP list to populate a form based on that.

 

Basically use my current lat and long to match that in the SP list (I'm aware getting these to be exact matches won't really work so will have to be in the vicinity of).

 

Has anyone done anything similar and can suggest a way to make this work?

 

Thanks in advance 

2 REPLIES 2
mdevaney
Super User III
Super User III

@KathrynHughes 
For example, lets say you have an asset in your table like this called 'Assets Table'.

 

Asset (text) Latitude (number) Longitude (number)
Flamethrower 100.000100 50.000500

 

 

Now place a gallery on your app's screen with this code in the Items property with some code like this.

Filter('Assets Table',
    Latitude + 0.000100 >= Location.Latitude
    And Latitude - 0.000100 <= Location.Latitude
    And Longitude + 0.000100 >= Location.Longitude
    And Latitude - 0.000100 <= Location.Latitude
)

 

You'll want to adjust the numbers according to the range you want to find assets within.

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

tgibso2
Frequent Visitor

Hi Kathryn,

 

I've developed something similar. I have a SharePoint list with the location name, latitude and longitude. I import this into a collection using:

ClearCollect(Collection1, 'SharePoint List');

 

From there I add another action to create a second collection with an additional column that calculates the distance between the user and the site:

ClearCollect(Collection2,
AddColumns(Collection2,"Distance",
Acos(Cos(Radians(90-(Value(Latitude)))) *Cos(Radians(90-(Location.Latitude))) +Sin(Radians(90-(Value(Latitude)))) *Sin(Radians(90-(Location.Latitude))) *Cos(Radians((Value(Longitude))-(Location.Longitude)))) *6371))

Using the equation from this website.

"Latitude" and "Longitude" are the column headings for the site locations from Collection1 (i.e. the SharePoint List).

 

Then I can create a drop down sorted by distance:

Distinct(SortByColumns(Collection2,"Distance"),LocationName)

 

Hope that helps!

 

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

PA Community Call

Power Apps Community Call

Next call is happening on April 21st at 8a PST.

secondImage

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV STudio

Power Platform ISV Studio

ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Top Solution Authors
Top Kudoed Authors
Users online (87,991)