Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. export const getUserLocation = (user) => async dispatch => {
  2.  
  3. // asking user for permission to fetch thier current location
  4. let { status } = await Permissions.askAsync(Permissions.LOCATION);
  5. if(status !== 'granted'){
  6. dispatch({ type: USER_DENIED_ACCESS })
  7. }else {
  8. if(Platform.OS !== 'ios'){
  9. // if AndroiedLocation is GPS is closed open location form settings page
  10. const AndroiedLocation = await Location.getProviderStatusAsync();
  11.  
  12. if(!testo.locationServicesEnabled){
  13. await IntentLauncherAndroid.startActivityAsync(
  14. IntentLauncherAndroid.ACTION_LOCATION_SOURCE_SETTINGS
  15. )
  16. }
  17. }
  18. let location = await Location.getCurrentPositionAsync({enableHighAccuracy: true})
  19. let locationArray = [ 37.4015, -122.104641]
  20. let uid = user.uid
  21.  
  22. // saving loaction to database using geoFire
  23. const geoFireRef = await new GeoFire(firebase.database().ref('geoData'))
  24. geoFireRef.set(uid, locationArray)
  25. dispatch({ type: FETCHED_USER_LOCATION_SUCCESSFULLY, payload: location })
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement