[英]Rails 5: Access to geolocation was blocked over insecure connection to http://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.