我在React/Redux上编写我的Web应用程序。我需要借助Geolocation API获取用户位置信息。在桌面浏览器上一切正常,但在手机上(在小米红米Note 3和iPhone 5s上签出),它会抛出错误代码1 - 权限被拒绝。它不要求任何权限来获取位置。 地理位置API在手机上不起作用
下面是我在我的网站跑了测试样品:
componentDidMount() {
if (window.navigator.geolocation) {
window.navigator.geolocation.getCurrentPosition(position => {
alert(position.coords.latitude + ' ' + position.coords.longitude);
}, err => {
alert('ERROR: ' + err.code);
});
} else {
alert('Geolocation API is not supported!');
}
}
这是什么问题的解决?
你检查操作系统和/或浏览器设置,以确保在OS级别或应用程序级别上允许地理定位? –
@PatrickEvans是的。 [这里](https://html5demos.com/geo/)它会抛出权限请求(警告窗口接受/拒绝),但在我的网站上它不起作用。 –
请确保你没有意外阻止你自己的网站,一旦你阻止请求不会回来,直到该设置被清除 –