Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Place model */
- module.exports = {
- attributes: {
- name: {
- type: 'string',
- required: true
- },
- // This is the attribute used for the place's geolocation.
- // Be careful to store it as [ lng, lat ] or else geoNear queries will give imprecise results.
- coordinates: {
- type: 'json',
- required: true
- }
- },
- /**
- * Find places closer than a certain distance (in km) from a specified location [ lng, lat ].
- * @param conditions
- * JSON object should look like this:
- * {
- * lng: -72.213,
- * lat: 45.012,
- * maxDistance: 100,
- * limit: 20,
- * }
- *
- * @param callback (err, results)
- * Returns an array of results (ordered by increasing distance), it looks like this:
- * [
- * {
- * dis: 10.321,
- * obj: { JSON object of Place }
- * },
- * {
- * dis: 20.123,
- * obj: { JSON object of Place }
- * }
- * ]
- */
- findNear: function (conditions, callback) {
- Place.native(function (err, collection) {
- if (err) return callback(err);
- collection.geoNear({
- type: "Point" ,
- coordinates: [ conditions.lng, conditions.lat ]
- }, {
- limit: conditions.limit || 30,
- maxDistance: conditions.maxDistance * 1000.0,
- distanceMultiplier: 0.001,
- spherical : true
- }, function (err, places) {
- if (err) return callback(err);
- return callback(null, places.results);
- });
- });
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement