我使用导航器获取当前位置在页面加载谷歌地图上,但是当我在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?
我已经提到这在我的问题:我有研究,发现getCurrentPosition()和watchPosition ()在不安全的来源上被弃用。有没有其他方法可以做到这一点? –
不需要。如果您想在Chrome版本50或更高版本中使用HTML5地理位置,则必须使用安全来源。 – geocodezip
有没有没有HTTPS的解决方案? –