0

So I'm trying to retrieve entries based on their location/coordinates, within a given radius. And have been successful using this :

$query = new \Contentful\Delivery\Query;
    $query->setContentType('store')
    ->where('fields.location[within]', '-37, 144, 50');

However, the order in which they are returned aren't ordered by their distance to the given centre of the radius. Any help please? Thanks.

thebfftim
  • 109
  • 1
  • 6
  • Take a look at https://stackoverflow.com/questions/574691/mysql-great-circle-distance-haversine-formula. – chris85 Sep 28 '17 at 04:24

1 Answers1

1

The within operator doesn't do any sorting, unlike the near operator. If you're trying to use within in the context of a circular area, which seems to be what you're doing, you can replace it with near and it should work the way you want it:

fields.foo[near]=x,y,radius

The radius parameter can be used to limit the search area. Give it a try, let me know if this helps!

Davide

Davide Borsatto
  • 103
  • 1
  • 5