地理定位在Jsfidle中工作,但不在任何其他JS编辑器中

Geolocation working in Jsfiddle but not in any other JS editor?

本文关键字:任何 编辑器 其他 JS 工作 定位 Jsfidle      更新时间:2023-09-26

当我在Jsfidle上使用Gelocation代码示例或在谷歌开发者网站上使用谷歌演示示例时,我可以获得纬度和经度,但当我在其他一些JS编辑器中使用该代码时,我会收到错误地理定位服务失败

这是我的代码

if (navigator.geolocation) {
var latitude = '';
var longitude = '';
navigator.geolocation.getCurrentPosition(function (position) {
    latitude = position.coords.latitude;
    longitude = position.coords.longitude;
    alert(latitude);
     });
     } else {
    alert("Geolocation API is not supported");
    };

您使用Chrome50吗?他们删除了对非https网站的GeoLocation支持。但是(http://localhost:xx)仍被列入开发的白名单

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