web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Searching a list of lo...
Power Apps
Unanswered

Searching a list of locations and displaying the nearest (UK postcode)

(0) ShareShare
ReportReport
Posted on by 15

I've got a list of 300+ locations that I would like to allow a user to search by entering their postcode and then the app displaying the results by nearest first.

I've got the first few steps sorted, and an output into a gallery which automatically goes to alphabetical order based on the location name. This shows up fine, along with the miles to each location from the entered postcode.

However when I try to organise it by mileage I get the error "one or more locations specified in the waypoint parameter are invalid or require more information"

I'm using 


SortByColumns(SiteDistance,"Miles",SortOrder.Ascending)


for the gallery and a button with the OnSelect function below to populate the collection "SiteDistance"

 

ClearCollect(SiteList,Directory);
ClearCollect(SiteDistance, AddColumns(SiteList, "Miles", Value(Round(BingMaps.GetRouteV2(TextInput1.Text,postcode,{distanceUnit:"Mile"}).travelDistance,0))))

 

I'm fairly new to this so learning as I go, I'd appreciate some guidance on what's missing, and why it works when there's no sorting, but the error happens when I try and sort it by nearest first.

Many thanks



Categories:
I have the same question (0)
  • RobPL Profile Picture
    15 on at

    A bit more digging and I found a couple of postcodes that didn't return a result. In the initial results, it returned a blank distance, but when I tried to order them by distance, it created the error 👍

  • Verified answer
    v-jefferni Profile Picture
    on at

    Hi @RobPL ,

     

    If you want to bypass the error when postcodes are invalid, you can use below formula for the Gallery:

    SortByColumns(
     AddColumns(
     Directory, 
     "Miles", 
     Value(
     Round(
     IfError(
     BingMaps.GetRouteV2(
     TextInput1.Text,postcode, 
     {distanceUnit:"Mile"}
     ).travelDistance,
     -1
     ),
     0
     )
     )
     ),
     "Miles",
     SortOrder.Ascending
    )

     

    So, when a postcode is invalid, the distance in the Gallery display as -1 and let users know something is wrong.

     

    Best regards,

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 757 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 322 Super User 2025 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 209 Super User 2025 Season 2

Last 30 days Overall leaderboard