我正在尝试将 lat, lng 存储在我的模型中。我已将我的模型定义为
attributes: {
    point: {type: 'json'}
}  
我将坐标简单地传递为[x,y]。但它将点存储为NULL。所以请,如果有人知道如何处理它,请帮助我。我不知道该怎么做。
我正在尝试将 lat, lng 存储在我的模型中。我已将我的模型定义为
attributes: {
    point: {type: 'json'}
}  
我将坐标简单地传递为[x,y]。但它将点存储为NULL。所以请,如果有人知道如何处理它,请帮助我。我不知道该怎么做。
我尝试使用更时髦的字段类型来做类似的事情,但发现将其分解为原始类型效果更好。
module.exports = {
  attributes: {
    speed: {
      type: 'string'
    },
    heading: {
      type: 'string'
    },
    altitude: {
      type: 'string'
    },
    altitudeAccuracy: {
      type: 'string'
    },
    longitude: {
      type: 'float',
      required: true
    },
    latitude: {
      type: 'float',
      required: true
    },
    accuracy: {
      type: 'string'
    }
  }
};
这是存储地理数据的完整对象。
当您将地理位置作为 JSON 属性时,您可以像这样存储位置:
{ "type": "Point", "coordinates": [ 7.88, 47.78 ] } }
然后,当您在 MongoDB 中在此字段上创建2dsphere索引时
db.collection.createIndex({ geolocation: "2dsphere" })
您可以使用MongoDBs 空间查询。