小编tro*_*ers的帖子

navigator.geolocation getCurrentPosition未在Chrome Mobile中更新

我创建了一个专为智能手机设计的网站(可在http://dev.gkr33.com上访问),并尝试使用navigator.geolocation api并通过getCurrentPosition获取您的位置.这似乎最初工作,但是如果你试图刷新页面,它总是带回最后的GPS位置.我在页面上添加了一些调试信息,用于获取getCurrentPosition返回的时间,在初始定位之后,它总是返回相同的时间(下降到毫秒).

这似乎只发生在Chrome Mobile中.如果我通过Android浏览器浏览网站,它每次都可以正常工作.

代码如下所示;

<script type="text/javascript">
    (function ($) {
    $(document).ready(function() {
        var options = { enableHighAccuracy: true, maximumAge: 0, timeout: 60000 };
        var position;

        // empty the current html elements, not strictly necessary but
        // I'm clutching at straws
        $('#debug-latlng').empty();
        $('#debug-time').empty();
        $('#debug-address').empty();

        // Let's try and find out where we are
        if(navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(gotPos, gotErr, options ); 
        } else {
            gotErr();
        }

        // We've got our position, let's show map and update user
        function gotPos(position) {
            var …
Run Code Online (Sandbox Code Playgroud)

mobile google-chrome geolocation page-refresh

7
推荐指数
1
解决办法
6233
查看次数

标签 统计

geolocation ×1

google-chrome ×1

mobile ×1

page-refresh ×1