Created
September 6, 2019 02:23
-
-
Save zi6xuan/676ddca6da8e1f867049b107db81f798 to your computer and use it in GitHub Desktop.
The RN obtains the location function, automatically checks and requests permissions
This file contains 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
export async function getCurrentPosition(onSuccess, onError, error3) { | |
if (isAndroid) { | |
const granted = await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION); | |
if (!granted) { | |
PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION) | |
.then((status) => { | |
if (status == PermissionStatus.granted) { | |
// | |
getCurrentPosition(onSuccess, onError, false); | |
} | |
console.log('Location=' + status); | |
}).catch((status) => { | |
console.log('Location=' + status); | |
}); | |
return; | |
} | |
} | |
GeoLocation.getCurrentPosition( | |
(position) => onSuccess(position), | |
(err) => { | |
if (err.code === 3 && !error3) { | |
getCurrentPosition(onSuccess, onError, true); | |
} else { | |
onError(err); | |
} | |
}, | |
{ enableHighAccuracy: !error3, timeout: 1000 }, | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cool, Thanks.