[英]Parse Cloud Code GeoPoint
I have a Parse App which has two basic objects. 我有一个解析应用程序,它具有两个基本对象。 The first object "User" has a property called "location" which stores a GeoPoint.
第一个对象“用户”具有一个称为“位置”的属性,该属性存储GeoPoint。
The second object is "Sighting" which has a "location" property with a GeoPoint. 第二个对象是“瞄准”,它具有带有GeoPoint的“位置”属性。
In my cloud code I have sucessfuly introduced an aftersave function on the "Sighting" object so that a push notification is sent to everybody once a sighting has been saved. 在我的云代码中,我成功地在“瞄准”对象上引入了一个后保存功能,以便一旦保存了瞄准,便将推送通知发送给每个人。
However what I am trying to achieve is only sending those users within a certain range. 但是,我试图实现的只是在一定范围内发送这些用户。
I have found query.withinKilometeres but I cannot understand how to compare all User."Locations" and take the saved object "Location" as the base. 我找到了query.withinKilometeres,但是我不明白如何比较所有User。“ Locations”并以保存的对象“ Location”为基础。 Thereafter send all returned users a push.
之后,向所有返回的用户发送推送。
The cloud code is totally alien to me so any help is appreciated. 云代码对我来说是完全陌生的,因此可以提供任何帮助。
Thanks 谢谢
James 詹姆士
The target of push is _Installation. 推送的目标是_Installation。 In your question, you should maintain a pointer 'user' for related currentUser of the device.
在您的问题中,您应该为设备的相关currentUser维护一个指针“ user”。
//afterSave of Sighting
var sighting = request.object;
//means created, not update
if(!sight.existed()){
var location = sighting.get('location');
var userQuery = new Parse.Query(Parse.User);
//1 for example
userQuery.withinKilometeres('location', 1);
var query = new Parse.Query(Parse.Installation);
query.matchesQuery('user', userQuery);
Parse.Push.send({
where:query,
data:{
alert: "this is msg",
title: "this is title"
}
},{useMasterKey:true})
.then(function(){
console.log('push done');
}, function(error){
console.error(error);
});
}
There are a limitation of matchesQuery. matchsQuery有一个限制。 In this case, you cannot send more than 1000 user (to get related installations).
在这种情况下,您发送的用户数不能超过1000(以获取相关的安装)。
So I suggest you put location info in _Installation, and it more make sense(Your user may have multiple device, but User cannot split to 2 places) 因此,我建议您将位置信息放在_Installation中,这样更有意义(您的用户可能有多个设备,但用户无法拆分到2个位置)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.