使用云功能通知半径 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 (将#修改为@)