2016-05-24 49 views
-2

我使用导航器获取当前位置在页面加载谷歌地图上,但是当我在Firefox运行我的代码它返回当前位置的经纬度和工作正常,相同的代码是不适用于Google Chrome浏览器。navigator.geolocation不能在Google Chrome中工作

我有研究,发现getCurrentPosition()和watchPosition()在不安全的起源上被弃用。 注: 请参阅此链接:Geolocation API removed from unsecured origins in Chrome 50

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.3/jquery.min.js"></script> 
<script type="text/javascript"> 
// Function for showing current postion on the map 
    $(document).ready(function() { 
     if (navigator.geolocation) { alert('fn called'); 
      navigator.geolocation.getCurrentPosition(showPosition); 
     } 
    }); 
    function showPosition(position) { 
     var latitude = position.coords.latitude; 
     var longitude = position.coords.longitude; 
     console.log('navigation called');console.log(latitude);console.log(longitude); 
    } 

</script> 

有没有人面对它,我不想使用HTTPS?

回答

0

您必须从https://为地理位置提供页面才能使用最新版本的Chrome。

看到这个相关链接:Geolocation API removed from unsecured origins in Chrome 50

从上面的链接:

使用Chrome 50起,Chrome浏览器不再支持从非传递页面获取使用HTML5 Geolocation API用户的位置(https://developers.google.com/web/fundamentals/native-hardware/user-location/obtain-location?hl=en) - 安全连接。这意味着进行地理定位API调用的页面必须来自secure context,如HTTPS

+0

我已经提到这在我的问题:我有研究,发现getCurrentPosition()和watchPosition ()在不安全的来源上被弃用。有没有其他方法可以做到这一点? –

+0

不需要。如果您想在Chrome版本50或更高版本中使用HTML5地理位置,则必须使用安全来源。 – geocodezip

+0

有没有没有HTTPS的解决方案? –

0

地理位置api是否从手机版本中删除?当我检查出我的iPhone 5与ios 9,铬50.0.2661.95版本,仍然有网页的地理位置请求与http

相关问题