Complete the sorting function, now it can find portals within a given range