如何在流星架构中实现地理定位

时间:2016-11-21 16:20:02

标签: meteor collections meteor-autoform

我正在使用最新版本的meteor,我已经创建了一个架构,我想在架构中添加一个位置。我想知道使用autoform将位置保存到集合中的最佳实践是什么,最终根据地理位置和邻近度进行查询。

1 个答案:

答案 0 :(得分:0)

最新的Meteor附带Mongo 3.2

Mongo 3.2使用GeoJSON让您使用不同类型的几何体描述位置。例如,您可以将位置标识为空格中的点,如:

{
  location: {
    type: "Point",
    coordinates: [-73.856077, 40.848447]
  },
  name: "Morris Park Bake Shop"
}

或多边形如:

{
  geometry: {
    type: "Polygon",
      coordinates: [[
       [ -73.99, 40.75 ],
         ...
       [ -73.98, 40.76 ],
       [ -73.99, 40.75 ]
      ]]
  },
  name: "Hell's Kitchen"
}

这使您可以进行如下复杂的查询:

const neighborhood = Neighborhoods.findOne({geometry: {$geoIntersects: {$geometry: {type: "Point", coordinates: [ -73.93414657, 40.82302903 ]}}}});
const restaurants = Restaurants.find({location:{$geoWithin:{$geometry: neighborhood.geometry}}})

(来自此mongo tutorial的例子)

这是mongo推荐的使用索引和分片支持来保存地理空间数据的方法。

有一个autoform地图插件:https://github.com/yogiben/meteor-autoform-map/ - 具有GeoJSON支持

相关问题