如何解决使用云功能通知半径 5 公里范围内的用户
我正在开发客户端专业匹配应用。我在 firestore 中有“客户”集合,当客户(在某个领域寻找专业人士)注册并创建文档时,我想在目标领域中搜索居住在半径 5 公里范围内的专业人士的“专业人士”集合并使用云功能向他们发送通知。我计划将 geofire.js 用于云功能,但我愿意接受任何其他建议或方法来实现这一点。这是我在 index.js
中的代码,我不知道如何在 geofire 部分编写代码来实现这一点。所以请帮助我处理 geofire 部分中的代码,但它不一定与 geofire 相关。任何帮助将不胜感激。
exports.sendNotification = functions.firestore
.document("users/{user}/clients/{client}")
.onCreate(async (snapshot,context) => {
try {
const clientfield = snapshot.data().field;
const clientcoordinates =
snapshot.data().coordinates;
await admin.firestore().collection("pros")
.where('field','==',clientfield).get()
.then(querySnapshot => {
const tokenArray = [];
// need code to find pros in the target field who live
// within 5 km from the new client here
tokenArray.push(snapshot.val().FCMToken)
})
}
return admin.messaging().sendToDevice(tokenArray,payload)
} catch (error) {
console.log(error)
}
})
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。