Skip to content

Instantly share code, notes, and snippets.

@phuochau
Last active March 6, 2018 04:51
Show Gist options
  • Save phuochau/f860cbebe78993969fbf1d350be8d5f6 to your computer and use it in GitHub Desktop.
Save phuochau/f860cbebe78993969fbf1d350be8d5f6 to your computer and use it in GitHub Desktop.
This is an example for Geofire and Firebase
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