在 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
});
}
EDIT:The pop up never appeared in IOS for me because I was adding the Privacy message info to the wrong info.plist file. It needs to go here:
编辑:在 iOS 中对我有用的另一项修复是:
- 点击模拟器上的主页按钮
- 单击设置
应用程序>隐私>定位服务>我的应用程序
- 然后确保“使用时
该应用程序”已被检查
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)