1
我正在使用流星的最新版本,並且我創建了一個模式,並且我想向該模式添加一個位置。我想知道使用autoform將位置保存到集合的最佳做法,並最終基於地理位置和鄰近度進行查詢。如何在流星模式中實現地理位置
我正在使用流星的最新版本,並且我創建了一個模式,並且我想向該模式添加一個位置。我想知道使用autoform將位置保存到集合的最佳做法,並最終基於地理位置和鄰近度進行查詢。如何在流星模式中實現地理位置
最新的流星帶有蒙戈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推薦的方法來保存geos具有索引和分片支持的空間數據。
有一個autoform地圖插件:https://github.com/yogiben/meteor-autoform-map/ - 支持GeoJSON