【发布时间】:2016-07-18 14:50:25
【问题描述】:
我正在尝试获取距中心点 200m 范围内的所有文档,但出现此错误
来自子 getLocNearMe id hg3jRDv8onsZEGvBM 的异常错误:异常 轮询查询时 {"collectionName":"Col_Location","selector":{"loc":{"$near":{"$geometry":{"type":"Point","coordinates":[1.3852457,103.88112509999999]}, "$maxDistance":200}}},"options":{"transform":null}}: $near 需要一个点,给定 { 类型:“点”,坐标:[ 1.3852457, 103.8811251] }
客户端/组件/map.jsx
navigator.geolocation.getCurrentPosition(function (pos) {
const sub = Meteor.subscribe("getLocNearMe", pos.coords.latitude, pos.coords.longitude)
Tracker.autorun(function () {
if (sub.ready()) {
Data.MarkersRawData = Col_Location.find().fetch()
}
})
})
lib/collections.jsx
Meteor.publish("getLocNearMe", function(lng, lat) {
check(lat, Number)
check(lng, Number)
const data = Col_Location.find({
loc: {
$near: {
$geometry: {
type: "Point" ,
coordinates: [lng, lat]
},
$maxDistance: 200
}
}
})
console.log(data)
if (data) {
return data
}
return this.ready()
})
服务器/server.jsx
Col_AllQuestion._ensureIndex({"loc": "2dsphere"})
Col_Location.insert({
loc: {
type: "Point",
coordinates: [103.8, 1.31]
}
})
【问题讨论】: