我已经在两天内处理了此错误,但仍然找不到解决方案。因此,我决定将其发布在此处的堆栈溢出中。顺便说一句,我正在使用Android版本为8.1的物理设备
这是我在控制台中收到的错误:
“ console.error:{TIMEOUT':3,” POSITION_UNAVAILABLE“:2,” PERMISSION_DENIED“:1,” message“:”位置请求超时“,”代码“:3}
这是代码:
state = {
focusedLocation: {
latitude: 37.7900352,
longitude: -122.4013726,
latitudeDelta: 0.0122,
longitudeDelta: (Dimensions.get('window').width / Dimensions.get('window').height) * 0.0122,
},
//this is for the marker location
locationChosen: false,
};
getUserLocationHandler = () => {
navigator.geolocation.getCurrentPosition(
pos => {
const coordsEvent = {
nativeEvent: {
coordinate: {
latitude: pos.coords.latitude,
longitude: pos.coords.longitude,
},
},
};
this.pickLocationHandler(coordsEvent);
},
err => {
console.log(err);
alert('Tangina mo bobo');
},
{
enableHighAccuracy: true,
timeout: 10000,
maximumAge: 0,
}
);
}
render() {
let marker = null;
if (this.state.locationChosen) {
marker = <MapView.Marker coordinate={this.state.focusedLocation} />;
}
return (
<View style={styles.container}>
<MapView
initialRegion={this.state.focusedLocation}
style={styles.map}
onPress={this.pickLocationHandler}
ref={ref => (this.map = ref)}
>
{marker}
</MapView>
<View style={styles.button}>
<Button title="Locate me!" onPress={this.getUserLocationHandler} />
</View>
</View>
);
}
这些是我在Android Manifest中的许可:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
随时询问您是否要检查一些代码或其他内容。