确定是否使用React Native启用地理定位 [英] Determining if geolocation enabled with react native
问题描述
使用RN构建应用程序我使用以下方法来接收用户的位置:
Building an app with RN I use the following to receive user's location :
navigator.geolocation.getCurrentPosition(
(position) => {
//do stuff with location
},
(error) => {
//error or locaiton not allowed
},
{enableHighAccuracy: true, timeout: 20000, maximumAge: 1000}
);
哪个立即调用查询以使用户接受地理位置许可.我现在想要实现的是在提示用户单击按钮以接受那些权限之前,先有一个明确的屏幕.为了到达那里,我需要某种方式来检查他是否已经接受了这些权限.将其缓存在存储中将是一个糟糕的解决方案-如果用户更改设置的权限,则可能不同步.
Which immediately invokes the inquiry for user to accept geolocation permissions. What I'm trying to achieve now is to have an explicit screen before prompting user to click on a button to accept those permissions. In order to get there, I need some way to check if he has accepted those permissions before or not. Caching it in storage would be a bad solution - it might go out of sync if user changes permissions in settings.
如何在不触发权限警报的情况下检查用户是否已接受地理定位权限?
How can I check if user has accepted geolocation permissions without triggering the permission alert?
推荐答案
您可以使用此库 https ://github.com/yonahforst/react-native-permissions 检查用户是否已接受位置许可. 像这样:
You can use this library https://github.com/yonahforst/react-native-permissions to check if user has accepted location permission. Like this:
Permissions.getPermissionStatus('location')
.then(response => {
this.setState({ locationPermission: response })
})
这篇关于确定是否使用React Native启用地理定位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!