javascript - Google HTML 5 地理定位 'use my location' 仅适用于 Firefox

标签 javascript html google-chrome firefox geolocation

我有一个按钮,用于检查您的位置,然后向您显示最近的位置。

我已经让它在 Firefox 中完美运行,而且它之前不是在实时域上,而是在开发服务器上,我看到了一些资源支持这样的想法:它必须在实时域上才能进行 html 5 地理定位在 Chrome 中工作。

现在我们已经转移到真实域,结果仍然相同,只有 Firefox 可以工作,而在 Chrome 中,我很确定 Safari 会说“无法检索位置”,这意味着存在错误。我已确保检查 Chrome 不会阻止该网站请求我的位置(没有弹出窗口来单击“是/否”),尽管它在我的设置中肯定已激活。在不同的电脑上得到相同的结果。

有什么想法可以阻止这个吗?它位于实时域中。

这是我的代码:

function geoFindMe() {

var output = $('.location-use');

if (!navigator.geolocation){
   $(".location-use").html('Geolocation is not supported by your browser');
return;
}

 function success(position) {
 var latitude  = position.coords.latitude;
 var longitude = position.coords.longitude;

output.innerHTML = '<p>Latitude is ' + latitude + '° <br>Longitude is ' + longitude + '°</p>';

  //find nearest restaurant location from these lat n long
  NearestLoc( latitude, longitude );

};



 function error() {
   $(".location-use").html('Unable to retrieve your location');
 };

$(".location-use").html('Locating...');

  navigator.geolocation.getCurrentPosition(success, error);
 }

最佳答案

https://developers.google.com/web/updates/2016/04/geolocation-on-secure-contexts-only

这个答案在这里(感谢 user3186314),Chrome 需要 HTTPS

关于javascript - Google HTML 5 地理定位 'use my location' 仅适用于 Firefox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38291702/

相关文章:

javascript - 焦点在 Chrome 上的输入中不起作用

javascript - 提交按钮不提交

javascript - this.props.getItemCount 不是函数(VirtualizedList、React Native)

google-chrome - 仅使用 chrome 控制台运行 selenium 命令

jQuery DIV 重叠背景 DIV

html - CSS 背景颜色在悬停状态下不起作用

css - 转换时文本模糊 :rotate in Chrome

javascript - 将 Prop 传递给嵌套的子组件

javascript - 从字符串中删除日期

javascript - 当 JavaScript 执行时,Internet Explorer 6 中止页面请求