gpt4 book ai didi

html - navigator.geolocation : how to know if the user is being asked for location? 的可用性问题

转载 作者:行者123 更新时间:2023-11-28 03:44:12 27 4
gpt4 key购买 nike

HTML 的 navigator.geolocation 是否有“当前询问用户是否愿意共享位置”的事件处理程序?

我想显示一些文本,指示用户分享他们的位置当且仅当他们实际上被要求分享他们的位置。

目前我有这段代码,但它坏了。

第一次看起来很顺利,但第二次(当浏览器知道这是一个受信任的站点,所以不会询问用户是否共享他们的位置),“共享您的位置”在页面加载时快速闪烁,然后消失在 map 后面。

    // map.js
function gpsSuccess() {
// We have a location - although we don't know whether this is
// because the user has already agreed to share with this domain,
// or whether they have just this second been asked.
$('#sharelocation').hide();
// load map, etc
}
if (navigator.geolocation) {
watchId = navigator.geolocation.watchPosition(gpsSuccess, gpsFail);
}

// map.html
<div id="sharelocation">Share your location</div>
<div id="map" class="hidden"></div>

当且仅当他们实际上被要求分享他们的位置时,有没有关于在页面正文中向用户提供一些说明的顺利方法的建议?

最佳答案

除非执行失败回调,否则我会考虑不显示“共享位置”消息。

function gpsFail() {
$('#sharelocation').show();
}

您可以在 sharelocation block 中包含一条消息,解释如何启用位置共享、您将如何处理这些信息等。

关于html - navigator.geolocation : how to know if the user is being asked for location? 的可用性问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7934120/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com