Geolocation Sails.js根据地理位置坐标的距离查找

Geolocation Sails.js根据地理位置坐标的距离查找,geolocation,sails.js,sails-mongo,Geolocation,Sails.js,Sails Mongo,我在一个项目中使用了sails.js,该项目将显示用户位置附近的帖子,然而,虽然我在查找地址地理编码的引用和工具方面没有遇到任何问题,但我找不到任何关于从另一组坐标中按距离查找这些内容的信息,就像使用常规mongodb一样。我的位置模型是: module.exports = { attributes: { longitude: { type: 'float', required: true },

我在一个项目中使用了sails.js,该项目将显示用户位置附近的帖子,然而,虽然我在查找地址地理编码的引用和工具方面没有遇到任何问题,但我找不到任何关于从另一组坐标中按距离查找这些内容的信息,就像使用常规mongodb一样。我的位置模型是:

module.exports = {
    attributes: {
        longitude: {
            type: 'float',
            required: true
        },
        latitude: {
            type: 'float'
        },
        country: {
            type: 'string'
        },
        city: {
            type: 'string'
        },
        stateCode: {
            type: 'string'
        },
        zipcode: {
            type: 'string'
        },
        streetName: {
            type: 'string'
        },
        streetNumber: {
            type: 'string'
        }
    }
};

如何编写此模型的查找,以便在设定范围内按距离查找和排序?

sails mongo不支持使用$near,但是如果您确保您的模型设置如下,则可以使用.native函数:

attributes: {
location: {
    index: '2d',
    longitude: {
        type: 'float',
        required: true,
    },
    latitude: {
        type: 'float',
    }
},
...
有关更多信息,请参阅本文: