jch*_*241 11 google-chrome geolocation
我正在请求用户的地理位置navigator.geolocation
,但是我被抛出错误:
" https://www.googleapis.com/ "上的网络位置提供商:已返回错误代码400.
Chrome 54.0.2840.98上发生此错误.这在Firefox 50.0上没有问题.我正在使用http-server运行本地服务器
这是功能:
_getLocation: function() {
if (!navigator.geolocation) {
alert('Geolocation is not supported by this browser, maybe use a pop-up and ask user for zipcode?');
}
function success(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
this.setState({
location: {
latitude: latitude,
longitude: longitude
}
});
this._getWeather(this.state.location.latitude, this.state.location.longitude);
}
function error(err) {
console.warn('ERROR(' + err.code + '): ' + err.message);
this.setState({
location: 'ERROR(' + err.code + '): ' + err.message
});
}
navigator.geolocation.getCurrentPosition(success.bind(this), error.bind(this));
},
Run Code Online (Sandbox Code Playgroud)
小智 2
我不知道答案,但我注意到了这一点...我在 Visual Studio Code 中的命令提示符处使用 http-server -o 来运行它,当它在 Google Chrome 中出现时,我收到此错误,但是,如果我复制url ' http://127.0.0.1:8082/ ' 到剪贴板并关闭初始 Chrome 浏览器,从我的桌面打开一个全新的实例,然后粘贴到 url,它工作正常!
关于“新鲜”会话的某些内容按照我的预期正确使用了我的设置(允许任何网站跟踪我的位置),但通过 VSC 启动的其他方式却没有......仍在调查......
归档时间: |
|
查看次数: |
2711 次 |
最近记录: |