I'm using SQL Server as a data source. My powerapp is displaying items in a gallery. These items are being pulled from a view.
I want to be able to filter the gallery by distance less than or equal to a user entered location. I have a table in my SQL server that contains the latitude and longitude of every city and zip in the US. I can write either a scalar or table valued function to calculate distance using the haversine formula. Not sure which would be the best in this use case.
My half baked idea is that I could create a function and then add it to the view, and pass the location entered into powerapps into the parameter in my function.
How would I implement this such that I had a delegable query?
Could you please share a bit more about your scenario?
Do you want to calcualte the distance between the user's current location and the location user entered, then compare this calculated distance within your SQL Table, to filter these records whose are close to the end user?
Based on the needs that you mentioned, I think the Bing Maps connector could achieve your needs. Within your app, you could use the BingMaps.GetRoute() function to calculate the distance between two different locations. The sample formula as below:
Note: The LatitudeColumn and LongitudeColumn are columns in your SQL Table, which used to store the latitude and longitude value or every city. The LocationTextBox represents the Text box in your app where the end user could enter a location manually.
More details about Bing Maps connector in PowerApps, please check the following article: