【问题标题】:How do I implement geolocation in a meteor schema如何在流星模式中实现地理定位
【发布时间】:2017-04-05 02:45:27
【问题描述】:

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

【问题讨论】:

    标签: meteor collections meteor-autoform


    【解决方案1】:

    最新的 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 推荐的使用索引和分片支持保存地理空间数据的方法。

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

    【讨论】:

      猜你喜欢
      • 2014-08-20
      • 1970-01-01
      • 1970-01-01
      • 2016-08-08
      • 2014-09-11
      • 1970-01-01
      • 1970-01-01
      • 2015-11-26
      • 1970-01-01
      相关资源
      最近更新 更多