2016-09-15 145 views
0

我遇到了一个问题,我刚刚注意到并且从未见过我以前发布的代码。在js我打电话在Android设备上使用Chrome时出现的Modernizr错误

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.'); 
} 
+0

您是在http或https页面上运行此代码吗? – Patrick

+0

这是http不是https – JimboJones

回答

0

As of Chrome 50,您将不再能够从非HTTPS网页访问地理位置API。

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

+0

谢谢。 我会跟我的网络管理员进行设置。我查看了该网站,但没有看到为Windows IIS设置它的方法。 再次感谢,至少我知道这可以现在修复。 – JimboJones

+0

查看https://github.com/ebekker/ACMESharp – Patrick

相关问题