繁体   English   中英

已阻止通过安全连接将地理位置混合访问到https:// localhost:3000,无法访问地理位置

[英]blocked Access to geolocation was blocked over secure connection with mixed content to https://localhost:3000

我已经实现了devise omniauth设置,当我用Facebook,Twitter或google登录时, html5 geolocation返回一个position unavailable error 但是,当我以常规devise user身份登录时,效果很好! 使用社交媒体帐户登录后,如何允许在Rails应用程序上访问html5 geolocation

function getLocation() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(setGeoCookie,showError);
    } else {
        alert("Geolocation is not supported by this browser.");
    }
}


function showError(error) {
switch(error.code) {
    case error.PERMISSION_DENIED:
        window.location = window.location;
        window.alert("Permission denied");
        break;
    case error.POSITION_UNAVAILABLE:
        window.location = window.location;
        window.alert("Location information is unavailable.");
        break;
    case error.TIMEOUT:
        window.location = window.location;
        window.alert("The request to get user location timed out.");

        break;
    case error.UNKNOWN_ERROR:
        window.location = window.location;
        window.alert("An unknown error occurred.");
        break;
}
location.reload();
}

更新1

我将代码更改为以下内容,并且在浏览器控制台中收到以下错误:

Origin does not have permission to use Geolocation service
[blocked] Access to geolocation was blocked over secure connection with mixed content to https://localhost:3000.


function getLocation() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(success, error, options);
    } else {
        alert("Geolocation is not supported by this browser.");
    }
}


var options = {
    enableHighAccuracy: true,
    timeout: 5000,
    maximumAge: 0
};

function success(pos) {
    var crd = pos.coords;

    console.log('Your current position is:');
    console.log(`Latitude : ${crd.latitude}`);
    console.log(`Longitude: ${crd.longitude}`);
    console.log(`More or less ${crd.accuracy} meters.`);
}

function error(err) {
    console.warn(`ERROR(${err.code}): ${err.message}`);
}

关于如何解除阻止的任何想法?

这不是Rails问题,而是Javascript问题。 在模板,CSS或Javascript中的某个位置,您从http而不是https加载了某些内容。 使用浏览器的检查器查找罪魁祸首。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM