Hello Michael,
Due to the usage of NEAR you now have the distance stored in the attribute `distance` in each of your Is (/ userLocations). Therefore you can just use SORT on the `distance` attribute. But I think I'm not totally getting your AQL query:
So (59.371317762912, 18.162492521009) is a location, and for each of your users you have a number of locations. You now want to get a list of all users with their locations that are sorted by being near (59.371317762912, 18.162492521009)? If I understood your description correctly though, you want exactly one location per user – the one that is nearest to that point, right? So that would work as follows:
FOR userLocation IN NEAR(userLocations, 59.371317762912, 18.162492521009, NULL, "distance")
FILTER u._key == userLocation.userId
SORT userLocation.distance DESC
LIMIT 1
RETURN userLocation
Now you have the nearest userLocation for each of your users, right? If the user doesn't have a userLocation, it will be an empty array. If it has one or more, it will be an array with exactly one element.
Best Wishes
Lucas