小编Mat*_*avo的帖子

navigator.getCurrentPosition()在Firefox或Safari中均不起作用

我似乎无法在Firefox 65或Safari 10上使用navigator.getLocation()

function getLocation(user_radius) {

var geo_options = {
enableHighAccuracy: true, 
maximumAge        : 30000, 
timeout           : 27000
};

function error(err) {
console.warn('Cannot load user location. Make sure you gave permission to share location');
}

document.body.style.position = "absolute";

if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function (position) {

        lat0 = position.coords.latitude;
        long0 = position.coords.longitude;
        corefunction(user_radius);
    },error,geo_options);
} else {
    x.innerHTML = "Geolocation is not supported by this browser.";
}
}
Run Code Online (Sandbox Code Playgroud)

尽管Firefox要求访问位置,而Safari不要求访问位置,但它们都不会返回纬度或经度。Firefox和Safari日志:

*Cannot load user location. Make sure you gave.....*
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

是的,我授予了权限,是的,我都同时启用了定位服务。该代码可以在Opera,Chrome,IE和Edge中正常工作。

奇怪的是,即使有第三方页面,我也无法通过那些浏览器获取位置信息:

https://www.w3schools.com/html/tryit.asp?filename=tryhtml5_geolocation https://developer.mozilla.org/zh-CN/docs/Web/API/Geolocation_API …

javascript browser location

0
推荐指数
1
解决办法
483
查看次数

标签 统计

browser ×1

javascript ×1

location ×1