Liz*_*yaw 3 javascript permissions android google-maps react-native
所以我改变了地理位置,从'react-native-geolocation-service'现在开始我使用地理位置。所以我现在的问题是不确定我的 PermissionsAndroid 代码是否正确,因为没有显示位置权限对话框。每次我按下按钮时,console.log 中都会显示“未授予位置权限”,因此这意味着未授予权限。正如我所说,没有出现“权限”对话框。
我希望你们检查我的代码是否有错误。这些是我的代码:
hasLocationPermission = () => {
try{
const granted = PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
title: 'Location Permission',
message: 'You must to accept this to make it work.'
}
)
if(granted === PermissionsAndroid.RESULTS.GRANTED){
console.log('Location permission accepted.')
}else{
console.log("Location permission denied")
}
} catch (err) {
console.warn(err)
}
}
getUserLocationHandler = () => {
if(this.hasLocationPermission){
Geolocation.getCurrentPosition(
position => {
this.setState({
userLocation: {
latitude: position.coords.latitude,
longitude: position.coords.longitude,
latitudeDelta: 0.0622,
longitudeDelta: 0.0421,
},
});
},
err => console.log(err),
{
enableHighAccuracy: true,
timeout: 15000,
maximumAge: 10000
}
);
}
}
render() {
return (
<View style={styles.container}>
<FetchLocation onGetLocation={this.getUserLocationHandler}/>
<UsersMap userLocation={this.state.userLocation}/>
</View>
);
}
Run Code Online (Sandbox Code Playgroud)
“FetchLocation”是按钮,“UsersMap”是地图。
如果你们知道如何在应用程序像 Grab 应用程序一样打开之前显示权限对话框,那就更好了。谢谢你!
如果您想在我的代码或 build.gradles 中看到其他内容,请随时询问。谢谢你!
您是否在 AndroidManifest 文件中添加了权限?就像文档所说的那样。
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7141 次 |
| 最近记录: |