navigator.geolocation无法在谷歌浏览器中使用

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

我有研究,发现getCurrentPosition()和watchPosition()在不安全的起源上被弃用。 注意:请参阅此链接: 从Chrome 50中的不安全来源中删除地理位置API

  // 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); }  

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

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

请参阅此相关链接: 从Chrome 50中的不安全起源中删除地理位置API

从以上链接:

从Chrome 50开始,Chrome不再支持使用HTML5 Geolocation API获取用户的位置]( https://developers.google.com/web/fundamentals/native-hardware/user-location/obtain-location?hl=en )来自非安全连接提供的页面。 这意味着必须从安全上下文 (如HTTPS)提供进行Geolocation API调用的页面。

地理位置api是从移动版Chrome中删除的吗? 当我使用ios 9,Chrome 50.0.2661.95版本检查我的Iphone 5时,仍然从http网页获得地理定位请求