Reputation: 1155
There is a requirement to do a query for documents which are within a certain radius from a given point. If you use MongoDB as a database, you can do the following:
db.Location.find({loc: {$geoWithin: {$centerSphere: [[-110.111111, 30.333333], 10 / 3963.2]}}})
What would be the proper way to achieve the same using Loopback's Geopoint
, near
and lt
?
Crossposted here as well: https://groups.google.com/forum/#!topic/loopbackjs/ncG7NdJ-eEQ
Upvotes: 1
Views: 432
Reputation: 1205
Location.find({where: {loc: {near: [-110.111111, 30.333333], maxDistance: 10}}})
This will do where 'Location' is your model name. 'loc' is your location field. 'near' specifies center coordinates. and 'maxDistance' specifies area to cover.
Also, this is for 2d indexes.
Upvotes: 1