mehmet
mehmet

Reputation: 1588

Simple Firebase Rules about validation

I am using firebase database and collecting users with their GPS coordinates and last timestamp from server side. Such as

+users

  • userId

    • userLocation

    • lastTimestamp

Well I want add a firebase Rules which is a user can read only who close to him (for example around the 1 km) and in time (such as people who has been there in for 30 min ). Is that possible to solve in firebase rules segment with newData and validate comments?

Upvotes: 0

Views: 249

Answers (2)

I think its in geofire where you set the radius. I'm also new to firebase so I'm not really familiar with it. well check this one. https://github.com/firebase/geofire

Upvotes: 0

Enpi
Enpi

Reputation: 281

Store and retrieve the locations using geofire.

https://github.com/firebase/geofire-java

Setting location data

geoFire.setLocation("userId", new GeoLocation(37.7853889, -122.4056973));

Geo Queries

// 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);

And to add a time limit change the read rule for your specific data.

// only messages from the last 30 minutes can be read
".read": "data.child('timestamp').val() > (now - 18000000)",

Upvotes: 3

Related Questions