Skip to content

Instantly share code, notes, and snippets.

@zi6xuan
Created September 6, 2019 02:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zi6xuan/676ddca6da8e1f867049b107db81f798 to your computer and use it in GitHub Desktop.
Save zi6xuan/676ddca6da8e1f867049b107db81f798 to your computer and use it in GitHub Desktop.
The RN obtains the location function, automatically checks and requests permissions
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 },
)
}
@zhaiyjgithub
Copy link

cool, Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment