Query order by nearest using geopoints

Hi there, not sure if this has been addressed elsewhere but finding documentation on GeoPoints in general seems fairly thin on the ground - I followed this Geo-code your content: find documents around you! - Prismic very old blog which shows how to query nearby documents by geopoint and passing in coordinates and a radius. So far, so good. But I would also like them to be ordered by nearest to fartherest, but I can't find any documentation that would show how to do that. Any pointers of what to pass to ordering to get this behaviour? Thanks!

Hello @technology,

I'm Baptiste from the software development team and I'm happy to welcome you to the Prismic community.

The near predicate is supposed to order results from nearest to farthest from the given coordinates so there's no need to use the orderings parameter. I've just tested it out using three documents with GeoPoints and it's working on my side. Could you tell me whether it's working on your side? If that's not the case, could you please send me the request you're doing and maybe a subset of the documents concerned?

I look forward to hearing from you,
Baptiste

I think I have found what the issue was - as I was putting multiple queries together, if the near query wasn't first the order wouldn't be applied. So:

[geopoint.near('my.clubs.coordinates', latitude, longitude, 1000)]
[at('document.type', 'clubs')]
[any('my.clubs.league', leagues)] 

works, but putting the geopoint query at the end, it doesn't. :man_shrugging: Thanks for the help!

1 Like