Guest User

Untitled

a guest
Oct 17th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. hasLocationPermission = () => {
  2. try{
  3. const granted = PermissionsAndroid.request(
  4. PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
  5. {
  6. title: 'Location Permission',
  7. message: 'You must to accept this to make it work.'
  8. }
  9. )
  10. if(granted === PermissionsAndroid.RESULTS.GRANTED){
  11. console.log('Location permission accepted.')
  12. }else{
  13. console.log("Location permission denied")
  14. }
  15. } catch (err) {
  16. console.warn(err)
  17. }
  18. }
  19.  
  20. getUserLocationHandler = () => {
  21. if(this.hasLocationPermission){
  22. Geolocation.getCurrentPosition(
  23. position => {
  24. this.setState({
  25. userLocation: {
  26. latitude: position.coords.latitude,
  27. longitude: position.coords.longitude,
  28. latitudeDelta: 0.0622,
  29. longitudeDelta: 0.0421,
  30. },
  31. });
  32. },
  33. err => console.log(err),
  34. {
  35. enableHighAccuracy: true,
  36. timeout: 15000,
  37. maximumAge: 10000
  38.  
  39. }
  40. );
  41. }
  42. }
  43.  
  44. render() {
  45. return (
  46. <View style={styles.container}>
  47. <FetchLocation onGetLocation={this.getUserLocationHandler}/>
  48. <UsersMap userLocation={this.state.userLocation}/>
  49. </View>
  50. );
  51. }
  52.  
  53. <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Add Comment
Please, Sign In to add comment