在Android设备上使用Chrome时出现Modernizr错误

时间:2016-09-15 19:40:54

标签: android google-chrome geolocation modernizr

我遇到了一个我刚才注意到并且从未见过我之前发布的代码的问题。在js我打电话

navigator.geolocation.getCurrentPosition()...

我还编写了回调的成功和错误部分。我遇到的问题是在使用Chrome的Android设备上,我总是收到错误" [object PositionError]"

如果我在同一设备上使用Firefox就可以了。我测试的所有iOS设备也可以使用。

是否有其他人遇到此问题,如果是,您是否找到了解决方案。

这是我的完整代码块:

  if (Modernizr.geolocation) {
    navigator.geolocation.getCurrentPosition(
        function (position) {
            var lat = position.coords.latitude;
            var lng = position.coords.longitude;
            callback(lat, lng);
        }
        , function (err) {
            // 1 = PERMISSION_DENIED
            // 2 = POSITION UNAVAILABLE
            // 3 = TIMEOUT
            //if (err.code == err.PERMISSION_DENIED) {
            alert(err);
            alert('Current location could not be obtained from the device.\r\nCheck your GPS settings.');
            //}
        }
        , { timeout: 10000 }//10 secs.
    );
} else {
    alert('This device does not support GPS locations.');
}

1 个答案:

答案 0 :(得分:0)

As of Chrome 50,您无法再从非https网页访问地理位置API。

感谢Lets Encrypt之类的项目,您现在可以免费获得SSL证书。