【发布时间】:2015-08-16 06:24:58
【问题描述】:
将所有帖子(地理标记)拉到一定距离内的发布/订阅不起作用。目的是获取用户当前位置,然后使用pub(服务器计算)拉取相关数据+在router上使用sort进行排序。
js 中的助手/事件(这部分,我还在调整它,看看有什么用)
Template.postsList.onCreated(function() {
this.interval = Meteor.setInterval(function (){
var currentLocation = Geolocation.latLng();
if(currentLocation) {
Session.set('currentLocation', currentLocation);
}
}, 2000
);
Session.set('postSubmitErrors', {});
});
Template.postsList.helpers({
loc : function () {
return Session.get('currentLocation');... // may not be needed if get in router
Template.postsList.events({
postsByDistance : function() { // may not be needed if get in router
var loc = Session.get('currentLocation');...
终端给出的错误是
来自子帖子的异常ByDistance id bsWXKgw5QboNzCRXw 错误: 轮询查询时出现异常 {"collectionName":"posts","selector":{"loc":{"$near":{"$geometry":{"type":"Point","coordinates":{"currentLocation":{" lat":xxx,"lng":xxx}}},"$maxDistance":500}}},"options":{"transform":null}}: $near 需要一个点,给定 { 类型:“点”,坐标:{ 当前位置:{ lat: xxx, lng: xxx } } }
如果我将 pub 行更改为 [anything.lng,anything.lat],它会显示 lat 或 lng of undefined
当我更改 function() 中的参数时,有时会收到 Exception while polling query meteor 错误。
15 年 8 月 16 日 - 建议后更新:
新酒吧
Posts._ensureIndex({'loc' : '2dsphere'});
Meteor.publish('postsByDistance', function(options) {
check(options, Object);
return Posts.find({
loc: {
$near: {
$geometry: {
type: "Point",
coordinates: [currentLocation.lng, currentLocation.lat]
错误现在表明 currentLocation 未定义。但是我确实在助手中定义了?
我还认为在错误中它说我有"options":{"transform":null}},如果正确不应该出现?
【问题讨论】:
-
从您发布的错误看来,您正在传递对象作为
coordinates的值。你不应该使用一个包含两个数值的数组吗? -
@apendua 我试图用 currentLocation 传递它,它定义为 = geolocation.latlng() 应该返回一个数组。您能否建议我如何排除故障或测试错误?任何示例代码也会很棒
标签: javascript meteor geolocation iron-router