【问题标题】:Simple Firebase Rules about validation关于验证的简单 Firebase 规则
【发布时间】:2017-03-20 20:06:38
【问题描述】:

我正在使用 firebase 数据库并从服务器端收集用户的 GPS 坐标和最后一个时间戳。比如

+用户

  • 用户ID

    • 用户位置

    • 最后一个时间戳

好吧,我想添加一个火力基地规则,它是用户只能阅读靠近他的人(例如 1 公里左右)和及时(例如已经在那里待了 30 分钟的人)。是否可以在 firebase 规则段中使用 newData 解决并验证 cmets?

【问题讨论】:

  • 使用geofire查询特定半径

标签: android validation firebase firebase-realtime-database firebase-security


【解决方案1】:

使用 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)",

【讨论】:

  • geofire 看起来不错,但我想让它变得简单。例如坐标像这样 37.76... 和 -122.40.... 所以小数点后 2 位非常重要,例如 -+0.02 tolerans 将是我的回应。例如 37.78.... 和 -122.42.... 非常接近我的坐标。怎么能这样验证。我能解释一下吗? "data.child('latitude').val() > (myloc - 0.02)" && "data.child('latitude').val()
【解决方案2】:

我认为它在你设置半径的 geofire 中。 我也是firebase的新手,所以我不太熟悉它。 好检查这个。 https://github.com/firebase/geofire

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-26
    • 1970-01-01
    • 2020-11-04
    • 2010-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多