关于验证的简单 Firebase 规则
Simple Firebase Rules about validation
我正在使用 firebase 数据库并从服务器端收集用户及其 GPS 坐标和最后时间戳。如
+users
userId
userLocation
lastTimestamp
好吧,我想添加一个 firebase 规则,该规则是用户只能读取靠近他(例如 1 公里左右)和及时(例如已经在那里 30 分钟的人)的人。是否可以使用 newData 在 firebase 规则段中解决并验证评论?
我认为它在您设置半径的 geofire 中。
我也是 firebase 的新手,所以我不太熟悉它。
好检查这个。
https://github.com/firebase/geofire
使用 geofire 存储和检索位置。
https://github.com/firebase/geofire-java
设置位置数据
geoFire.setLocation("userId", new GeoLocation(37.7853889, -122.4056973));
地理查询
// creates a new query around [37.7832, -122.4056] with a radius of 0.6 kilometers
GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(37.7832, -122.4056), 0.6);
并添加时间限制更改特定数据的读取规则。
// only messages from the last 30 minutes can be read
".read": "data.child('timestamp').val() > (now - 18000000)",
我正在使用 firebase 数据库并从服务器端收集用户及其 GPS 坐标和最后时间戳。如
+users
userId
userLocation
lastTimestamp
好吧,我想添加一个 firebase 规则,该规则是用户只能读取靠近他(例如 1 公里左右)和及时(例如已经在那里 30 分钟的人)的人。是否可以使用 newData 在 firebase 规则段中解决并验证评论?
我认为它在您设置半径的 geofire 中。 我也是 firebase 的新手,所以我不太熟悉它。 好检查这个。 https://github.com/firebase/geofire
使用 geofire 存储和检索位置。
https://github.com/firebase/geofire-java
设置位置数据
geoFire.setLocation("userId", new GeoLocation(37.7853889, -122.4056973));
地理查询
// creates a new query around [37.7832, -122.4056] with a radius of 0.6 kilometers
GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(37.7832, -122.4056), 0.6);
并添加时间限制更改特定数据的读取规则。
// only messages from the last 30 minutes can be read
".read": "data.child('timestamp').val() > (now - 18000000)",