超时后关闭地理位置提示

2024-03-06

有什么办法可以自动关闭地理位置提示(比如5秒后)?

以下是我的功能:

setCurrentPosition() {


const geoOptions = {
  enableHighAccuracy: false,
  timeout: 2000, // Wait 2 seconds
  maximumAge: 2000   //  Valid for 2 seconds
};

if ('geolocation' in navigator) {
  navigator.geolocation.getCurrentPosition((position) => {
    this.findAddressByCoordinates(position.coords.latitude, position.coords.longitude);
  }, (positionError => {
    console.log('error');
    console.log(positionError);
  }), geoOptions );


  if (this.currentMapData === undefined) {
    this.isComponentsValid.emit(false);
  } else {
    this.isComponentsValid.emit(true);
  }

}}

No,一旦chrome的提示出现,就无法用代码关闭。用户将阻止或允许。

一个技巧是使用软提示而不是硬提示,这基本上意味着您将创建自己的类似外观的弹出窗口,以便您可以根据您的需要控制此弹出窗口(5 秒后隐藏它)。一旦用户同意在您的自定义弹出窗口上共享他的位置,您就可以显示真正的 chrome 弹出窗口。

欲了解更多信息,请阅读 Ux Collective 上这篇精彩的文章 -https://uxdesign.cc/ask-for-push-notification-opt-in-properly-you-have-only-one-chance-64d66fac618e https://uxdesign.cc/ask-for-push-notification-opt-in-properly-you-have-only-one-chance-64d66fac618e

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

超时后关闭地理位置提示 的相关文章

随机推荐