In one of my latest projects we have used PowerApps to create a location aware selection of stores – and I wanted to share my experience about how to do this.
So, I found an open data set about attractions, restaurants, hotels and much more in Copenhagen.
https://portal.opendata.dk/dataset/guidedanmark-oplevelser-overnantning-aktiviteter-i-hele-danmark
In order to get the data into PowerApps – I created an Excel workbook and used PowerQuery to import the data in a Table.
The Query to create the table is quite simple and contains a little renaming and removal of unwanted columns, and I only imported the rows that has an Latitude and Longitude.
let
Source = Json.Document(Web.Contents(“https://portal.opendata.dk/dataset/44ecd686-5cb5-40f2-8e3f-b5e3607a55ef/resource/23425a7f-cc94-4e7e-8c73-acae88bf1333/download/guidedenmarkcphenjson.json”)),
#”Converted to Table” = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#”Expanded Column1″ = Table.ExpandRecordColumn(#”Converted to Table”, “Column1”, {“Id”, “Created”, “CreatedBy”, “Modified”, “ModifiedBy”, “Serialized”, “Online”, “Language”, “Name”, “CanonicalUrl”, “Owner”, “Category”, “MainCategory”, “Address”, “ContactInformation”, “Descriptions”, “Files”, “SocialMediaLinks”, “BookingLinks”, “ExternalLinks”, “MetaTags”, “RelatedProducts”, “Places”, “MediaChannels”, “Distances”, “Priority”, “Periods”, “PeriodsLink”, “PriceGroups”, “PriceGroupsLink”, “Routes”, “Rooms”, “Capacity”}, {“Id”, “Created”, “CreatedBy”, “Modified”, “ModifiedBy”, “Serialized”, “Online”, “Language”, “Name”, “CanonicalUrl”, “Owner”, “Category”, “MainCategory”, “Address”, “ContactInformation”, “Descriptions”, “Files”, “SocialMediaLinks”, “BookingLinks”, “ExternalLinks”, “MetaTags”, “RelatedProducts”, “Places”, “MediaChannels”, “Distances”, “Priority”, “Periods”, “PeriodsLink”, “PriceGroups”, “PriceGroupsLink”, “Routes”, “Rooms”, “Capacity”}),
#”Expanded Address” = Table.ExpandRecordColumn(#”Expanded Column1″, “Address”, {“AddressLine1”, “AddressLine2”, “PostalCode”, “City”, “Municipality”, “Region”, “GeoCoordinate”}, {“AddressLine1”, “AddressLine2”, “PostalCode”, “City”, “Municipality”, “Region”, “GeoCoordinate”}),
#”Expanded GeoCoordinate” = Table.ExpandRecordColumn(#”Expanded Address”, “GeoCoordinate”, {“Latitude”, “Longitude”}, {“Latitude”, “Longitude”}),
#”Filtered Rows” = Table.SelectRows(#”Expanded GeoCoordinate”, each ([Latitude] null and [Latitude] 0)),
#”Removed Columns” = Table.RemoveColumns(#”Filtered Rows”,{“Municipality”, “Region”, “ContactInformation”, “Descriptions”, “Files”, “SocialMediaLinks”, “BookingLinks”, “ExternalLinks”, “MetaTags”, “RelatedProducts”, “Places”, “MediaChannels”, “Distances”, “Priority”, “Periods”, “PeriodsLink”, “PriceGroups”, “PriceGroupsLink”, “Routes”, “Rooms”, “Capacity”}),
#”Expanded Category” = Table.ExpandRecordColumn(#”Removed Columns”, “Category”, {“Name”}, {“Name.1”}),
#”Removed Columns1″ = Table.RemoveColumns(#”Expanded Category”,{“Owner”}),
#”Expanded MainCategory” = Table.ExpandRecordColumn(#”Removed Columns1″, “MainCategory”, {“Name”}, {“Name.2”}),
#”Renamed Columns” = Table.RenameColumns(#”Expanded MainCategory”,{{“Name.2”, “MainCategory”}}),
#”Removed Columns2″ = Table.RemoveColumns(#”Renamed Columns”,{“AddressLine2”}),
#”Renamed Columns1″ = Table.RenameColumns(#”Removed Columns2″,{{“Name.1”, “Category”}}),
#”Removed Columns3″ = Table.RemoveColumns(#”Renamed Columns1″,{“Created”, “CreatedBy”, “Modified”, “ModifiedBy”, “Serialized”, “Online”, “Language”})
in
#”Removed Columns3″
The Excel file is then saved in Onedrive for business.
Lets build the app
I use the Web studio.
And select the Blank app with a Phone layout
On the canvas I click the Connect to data and create a new connection that connects to Onedrive for Business and pick the Excel file
So now we have a connection to data in our App
And I insert the following controls
The first two labels show the my location as latitude and longitude, and the I inserted a slider with a min and max of 0 to 2000 as the radius in meters around my location. The label above my slider is just to show the selected radius.
Now we can insert a drop down and set the Items to the data connection and the column Name in that data connection and see it works.
Now we must filter the items based on our current location. In order to do this, we must filter our items. This can be done using the FILTER function.
The formula the uses the slider to modify the radius around our location
Filter(CopenhagenGuide, Value(Latitude, “en-US”) >= Location.Latitude – Degrees(Slider1/1000/6371) && Value(Latitude, “en-US”) = Value(Location.Longitude, “en-US”) – Degrees(Slider1/1000/6371/Cos(Radians(Location.Latitude))) && Value(Longitude,”en-US”) <= Location.Longitude + Degrees(Slider1/1000/6371/Cos(Radians(Location.Latitude))) )
And if I now limit the radius to 173 meters you can see I have 4 places nearby
If you want to add a map as well highlighting the selected Attraction you can do that as well
You can find the information to do that here – https://powerapps.microsoft.com/en-us/blog/image-control-static-maps-api/
If you want a copy of the PowerApp file you are welcome to add a comment or ping me on twitter @donsvensen and I will send it to you.
Hope you can use this – Power ON!
Nice Work! I just used in one of my apps. I think you have a type on your Items formula. I think it should be
Filter(CopenhagenGuide, Value(Latitude) >= Location.Latitude – Degrees(Slider1/1000/6371) && Value(Latitude) = Value(Location.Longitude) – Degrees(Slider1/1000/6371/Cos(Radians(Location.Latitude))) && Value(Longitude) <= Location.Longitude + Degrees(Slider1/1000/6371/Cos(Radians(Location.Latitude))) )
Hi Connor thx 🙂 glad to hear you could use it – I will fix the formula:-)
Great work! Exactly what I want to achieve with Powerapps and Dynamics CRM! Would you mind send me your app file to hiway2002@gmail.com? Many thanks in advance!! Cheers, Harrison
Hi Harrison – sure will send you a copy /Erik
Excellent work! This really helped me too – thanks for publishing it. Note that I only got it going with the following variation on the Filter:
Filter(CopenhagenGuide,
Value(Latitude) >= Location.Latitude – Degrees(Slider1/1000/6371) &&
Value(Latitude) = Value(Location.Longitude) –
Degrees(Slider1/1000/6371/Cos(Radians(Location.Latitude))) &&
Value(Longitude) <= Location.Longitude + Degrees(Slider1/1000/6371/Cos(Radians(Location.Latitude))) )
thx – glad you could make it work 🙂
HHmmm. Part of the filter formula is dropping out when I post – part of the 2nd and 3rd conditions…
Having some trouble on this one. Could you send your app file to toddgray13@hotmail.com? Thanks!
Hi Todd – have sent you a copy /Erik
Hola, Me podrías regalar la aplicación para estudiarla un poco mas a fondo.
Gracias
Hi I can send you the app if you supply me with an e-mail address /Erik
Just what I needed, but unfortunately it is not working. Can you send it to me? cbassandre@gmail.com
Thank you
Send to you by mail /Erik
Nice example, but somehow I can’t get it to work. Could you send me the example to juha_nnus@hotmail.com
Thanks a lot!
Send to you /Erik
I am having some troubles wih this one. Could you send the example to pahaisopaha@outlook.com, thanks.
Send to you by mail / Erik
What be interesting take on this solution is to check if user is within a location radius of a site a specific site – then output what that site is – that way it could be used throughout a app – i.e if used to test which office site a user is at, so a table with office1, office 2 and office 3 – the app then tests if user is in radius of each site and if at say office 3 – user is presented with office 3 information/screens/data etc.
Hi James,
That can be done using this solution/method.
You just need to check the number of locations returned by the filter function and if it’s 1 then you can set the default to that location otherwise prompt the user to select between the filtered locations
BR
Erik
Nice. But I also have problems to get this to work.
Could you send the example to hbo@thymors.dk
Sent /Erik
This is exactly the formula I have been searching for. I can’t quite get it to work for me though. Are you able to send it to me so I can pick it apart from my end? brad.reading@live.com
Thanks!
Hi Brad,
Just sent you a copy 🙂
Have a great day
Erik
Hi. Great article, I’m having so troubles with the Filter formula, too. Do you mind send me a copy to glm@gmx.ch? Thx!
Hi Gian,
Thx – I have mailed you a copy of the app.
BR
Erik
Great! Do you mind send me a copy of your app to takenovn88@gmail.com
Thank you so much!
Sent
/Erik
Such a great project! can you please email me a copy of it? my email is fbsx503@hotmail.com and I have a question, what if I want to search for users within that specified radius? I mean their locations are not static they keep moving. how can I do that. If they are within the radius I need to count their steps, otherwise, I should stop counting. any suggestions?
Great solution I’m struggling to get the formula to work, can I have a copy please. Thanks in advance.
Send me your email at es @ catmansolution . com and I will send you the app
Hi. Really enjoying learning this. I have a question. In my drop down I am trying to use a database table via a SQL Connector. My code looks like this : Filter(‘[Assets].[work_in_area]’,
Value(latitude) >= Location.Latitude – Degrees(Slider1/1000/6371) &&
Value(Latitude) = Value(Location.Longitude) –
Degrees(Slider1/1000/6371/Cos(Radians(Location.Latitude))) &&
Value(Longitude) <= Location.Longitude + Degrees(Slider1/1000/6371/Cos(Radians(Location.Latitude))) )
I am not sure where I specify the column that needs to show in the drop down box as my table has multiple columns and I am not sure how to select the one to display. Is it part of the filter, or somewhere else. Any pointers appreciated. Hope that makes sense. Thanks Andrew
Hi Andrew,
You can set the field you want to show in the property pane for the control you have filtered
https://eriksvensen.files.wordpress.com/2020/05/annotation-2020-05-19-170011.png?resize=107%2C107
Hope this helps you and glad to hear you liked the post
BR
Erik
Here is a better link 🙂
Would you please send me a copy of the app? I want to dissect it and see if I can build upon that. Thanks!
Getta818@gmail.com
Send you a copy
By the way, your post is awesome. I’m sure it has helped very many people. Great work.
thx 🙂
This looks great. I’m new enough to this I need to ask, I can apply this filter to say a gallery couldn’t I?
Absolutely – The example in the blog returns a table that you can use as datasource in a gallery
I can’t seem to get anything back. Can you send me a copy of the app please? vanvicklet@gmail.com
Sure – will do it tomorrow
I’d appreciate a copy of your application also… Thanks
kennyanibaba0907@gmail.com