Last active
March 6, 2018 04:51
-
-
Save phuochau/f860cbebe78993969fbf1d350be8d5f6 to your computer and use it in GitHub Desktop.
This is an example for Geofire and Firebase
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { user, profiles } = this.state | |
const swipedProfiles = await this.getSwiped(uid) | |
const geoFireRef = new GeoFire(firebase.database().ref('geoData')) | |
const userLocation = [user.geolocation.latitude, user.geolocation.longitude] | |
const geoQuery = geoFireRef.query({ | |
center: userLocation, | |
radius: distance | |
}) | |
geoQuery.on('key_entered', async (uid, location, distance) => { | |
log(uid + ' at ' + location + ' is ' + distance + 'km from the center') | |
const user = await FirebaseUsers.getOnce(null, uid) | |
let isExist = false | |
profiles.each((profile) => { | |
if (profile.uid === user.uid) isExist = true | |
}) | |
if (isExist) return | |
const profiles = [...this.state.profiles, user.val()] | |
const filtered = SearchFilter(profiles, this.state.user, swipedProfiles) || [] | |
this.setState({ profiles: filtered, isEmpty: filtered.length === 0 }) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment