Find only nearby places

Hey I have collection of places, it contains lon and lat.
I want to make a method the fetch and return only the nearby places to me. My arguments will be my current place(lon and lat) and radius(in miles).
Thanks you very much. I really stuck and don’t know how to make it.

by googling “meteor geolocation” ?

Wow so cool! Thanks!

This might help you:

Minimongo on the client does not support $near or any of the geo location queries. You need to use those on the server in the publish function

You are right. I should have said minimongo on the client only supports $near geospacial selector.

Unsupported selectors:

  • $elemMatch inside $all
  • geoqueries other than $near ($nearSphere, $geoIntersects, $geoWithin)

Check out https://github.com/meteor/meteor/blob/devel/packages/minimongo/NOTES

How should I make sort by distance?
The place that closest to me is first.

https://docs.mongodb.org/v3.0/reference/operator/query/near/

$near sorts documents by distance. If you also include a sort() for the query, sort() re-orders the matching documents, effectively overriding the sort operation already performed by $near. When using sort() with geospatial queries, consider using $geoWithin operator, which does not sort documents, instead of $near.

in your publish function you could add an additional field that would allow you to sort on the client.