navigator.geolocation不适用于谷歌浏览器 [英] navigator.geolocation not working in google chrome
问题描述
我使用导航器在页面加载时在谷歌地图上获取当前位置,但是当我在Firefox中运行我的代码时,它返回当前位置的经纬度,并且工作正常,相同的代码不适用于Google Chrome浏览器。 / p>
我有研究,发现getCurrentPosition()和watchPosition()在不安全的起源上被弃用。
注意:
请参阅此链接:
< script
< script type =text / javascript>
//在地图上显示当前位置的函数
$(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?
地理位置api是否从移动版本中移除了Chrome?当我使用ios 9检查Iphone 5时,Chrome 50.0.2661.95版本仍然从http
的网页获取地理位置请求
I am using navigator for getting current location on google map on page load but when I am running my code at Firefox its returning the latitude and longitude of current location and working fine, Same code is not working with Google Chrome browser.
I have research and found that getCurrentPosition() and watchPosition() are deprecated on insecure origins. Note: See this link: 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>
Has anyone face it before, I don't want to use HTTPS?
Is geolocation api removed from mobile versions chrome? As I checked out on my Iphone 5 with ios 9, chrome 50.0.2661.95 versions and still got geolocation requests from web pages with http
这篇关于navigator.geolocation不适用于谷歌浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!