2014-09-02 70 views
1

我一直在使用sails.js的项目,将显示用户位置附近的帖子,但是虽然我没有找到引用和工具来地址解析我找不到地址有关通过距离另一组坐标来找到这些信息的任何信息,这是您使用常规mongodb的方式。我的地方模式是:Sails.js通过距离地理位置坐标找到

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' 
     } 
    } 
}; 

我将如何组成这一模式的发现,以查找和排序由一组范围内的距离?

回答

1

帆 - 蒙戈不支持使用$附近,但是如果您确保模型设置如下,你可以使用.native功能:

attributes: { 
location: { 
    index: '2d', 
    longitude: { 
     type: 'float', 
     required: true, 
    }, 
    latitude: { 
     type: 'float', 
    } 
}, 
... 

看到这个帖子的详细资料:https://github.com/balderdashy/sails-mongo/issues/46