在Android模拟器中,下面的代码工作正常,但在iOS中,它甚至没有进入navigator.geolocation.getCurrentPosition。
我已通过调试菜单更新了我的模拟器的自定义位置,但如果它甚至没有进入navigator.geolocation.getCurrentPosition,我有点迷失。
constructor(props) {
super(props);
this.state = {
focusedLocation: {
latitude: 37.4219999,
longitude: -122.0862462,
latitudeDelta: 0.0022,
longitudeDelta: Dimensions.get("window").width / Dimensions.get("window").height * 0.0122,
},
};
}
componentDidMount() {
console.log("did mount: ", this.state.grumblersLocation.latitude); //triggers iOS and Android
navigator.geolocation.getCurrentPosition(pos => {
console.log("raw pos lat: ", pos.coords.latitude); //triggers in Android only
this.setState({
focusedLocation: {
...this.state.grumblersLocation,
latitude: pos.coords.latitude,
longitude: pos.coords.longitude
}
}, () => {
console.log("state after pos lat: ", this.state.grumblersLocation.latitude); //triggers in Android only
});
},
err => {
console.log("Fetching the Position failed: ", err); //Not triggering on either
});
}