启用后,Navigator Geolocation API将引发错误代码PERMISSION_DENIED

我为我的Angular 4项目使用了Navigator Geolocation API,下面是我使用它的一段代码:

setLocationByNavigator () { let options = {} const deviceInfo = this.deviceService.getDeviceInfo() if (deviceInfo.device === 'android' || deviceInfo.os === 'mac') { options = { maximumAge: 1500000, timeout: 100000 } } return new Promise((resolve, reject) => { navigator.geolocation.getCurrentPosition((position) => { resolve(position.coords) }, (error: PositionError) => { resolve(error) }, options) }) } getErrorCode (error: PositionError) { switch (error.code) { case error.PERMISSION_DENIED: console.info('Geolocation: User deinied the request for Geolocation.'); break; case error.POSITION_UNAVAILABLE: console.info('Geolocation: Location information is unavailable.'); break; case error.TIMEOUT: console.info('Geolocation: The request to get user location timed out.'); break; default: console.info('Geolocation: An unknown error occured.'); break; } } 

在Window下的桌面上工作完美。 但是对于Mac和iPhone来说不是。 我注意到,在Safari上启用地理位置后,控制台将引发error.PERMISSION_DENIED行。

该项目是在一个docker的容器,并在127.0.0.1地址代理(某处我读,这是一个解决scheme,有人将本地主机更改为127.0.0.1)

url: https : //microker-stage.dev.e-vista.hu/

Interesting Posts