Hello,
My app lists retail stores under our brand, currently my gallery filter uses Search and SortbyColumns. I would like to sort the gallery list by stores that are closest to the user (the device location). I was able to create a label that displays the KM distance in the gallery list item (Code #1). My trouble is getting the gallery filter to sort by that distance. I've tried nesting the "AddColumns" function to try and append the distance to the main table (Table1), the table comes from a static Excel data source which I think might be the problem.
Any help will be greatly appreciated, even a completely different approach to acheive this.
Thanks, Nick
Code #1 - working km distance label inside gallery list items
ACOS(Cos(Radians(90-DeviceLat))*Cos(Radians(90-ThisItem.Latitude))+Sin(Radians(90-DeviceLat))*Sin(Radians(90-ThisItem.Latitude))*Cos(Radians(DeviceLong-ThisItem.Longitude)))*6371
Code #2 - current working gallery filter
SortByColumns(Search(Table1,TextInput1.Text,"Address","City","Mall Name","Location / Dealer Name (Primary)","DBM/AM"),"Location / Dealer Name (Primary)")
Code #3 - not-working gallery filter where I try to sort gallery list items by distance instead of dealer/location name
SortByColumns(AddColumns('Table1',"Distance",Acos(Cos(Radians(90-DeviceLat))*Cos(Radians(90-Latitude))+Sin(Radians(90-DeviceLat))*Sin(Radians(90-Latitude))*Cos(Radians(DeviceLong-Longitude)))*6371),Search(Table1,TextInput1.Text,"Address","City","Mall Name","Location / Dealer Name (Primary)","DBM/AM"),"Distance",Ascending)