1

I have a Google Map on my site and am using W3 Geolocation to detect a users location when they click a button, "Get current location". Then it should popup with the allow/deny infobar at the top of the browser window.

I don't want to prompt all my visitors for Geolocation access but do want to somehow remember if a user has already allowed the Geolocation and run Geolocation if so.

From my research this isn't possible but I'm hoping someone has ran into this situation before. The only way I can figure this can be done is setting a cookie.

Thanks!

4

1 回答 1

1

这不完全是您想要的,但我认为它可能会有所帮助。

根据W3C 草案,如果未找到缓存值,您可以尝试从浏览器获取任何缓存值(无需用户确认)或回退到自定义方法。

假设用户同意提供地理位置,它将被缓存。来自同一 W3C 草案的示例:

// Request a position. We only accept cached positions, no matter what 
// their age is. If the user agent does not have a cached position at
// all, it will immediately invoke the error callback.
navigator.geolocation.getCurrentPosition(successCallback,
                                         errorCallback,
                                         {maximumAge:Infinity, timeout:0});
于 2011-11-11T15:19:46.450 回答