我已将所有用户的位置保存在安装对象中。我有另一个名为locationObject的对象,当当前用户发送当前位置时会更新。当它发生时,我想将他当前的位置与所有其他保存的位置进行比较,并向附近的用户发送推送通知。这是我的代码,但这似乎不起作用。
//this code should run when the locationObject is updated
Parse.Cloud.afterSave("locationObject", function (request) {
var geoPoint = request.object.get("myCurrentLocation");
var pushQuery = new Parse.Query(Parse.Installation);
pushQuery.near("significantLocationUpdate", geoPoint);
pushQuery.limit(100);
pushQuery.find({
success: function(results) {
if (results.length > 0) {
//console.log(JSON.stringify(results));
for (i = 0; i < results.length; 1++) {
Parse.Push.send({
where: pushQuery,
data: {
alert: "some user is nearby"
}
}, {
success: function() {
console.log("push was successfull")
},
error: function(error) {
console.log("sending push failed")// Handle error
}
});
}
} else {
console.log("failure");
}
},
error: function (error) {
console.log("error");
}
});
});
答案 0 :(得分:0)
这就是我重新构建代码的方式。它有效。感谢Paulw11
Parse.Cloud.afterSave("locationObject", function (request) {
var geoPoint = request.object.get("myCurrentLocation");
var pushQuery = new Parse.Query(Parse.Installation);
pushQuery.near("significantLocationUpdate", geoPoint);
pushQuery.limit(100);
Parse.Push.send({
where: pushQuery,
data: {
alert: "some user is nearby"
}
}, {
success: function() {
console.log("push was successful");
},
error: function(error) {
console.log("sending push failed")// Handle error
}
});
});