使用devise omniauth登录到Rails应用时,HTML5地理位置返回位置不可用错误

时间:2018-11-27 13:28:01

标签: javascript ruby-on-rails geolocation omniauth

我有一个Rails应用程序,其中已实现了针对Facebook,Twitter和Google的devom omniauth设计。另外,我还为用户提供了使用其电子邮件进行注册/登录的选项。

我已实现以下html5 geolocation以便根据用户的当前位置进行搜索。

当我不通过社交媒体帐户注册/登录电子邮件时,一切正常。但是,如果我使用社交媒体帐户登录,则html5 geolocation将从下面的Location information is unavailable

中抛出showError function
function getLocationOther() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(setLocCookie,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("Please click on allow, pinsle can’t search and find results without your current location. If this message still appears even after you click on allow, then you need to enable the location services on your device. For more information on how to enable the location services,please go to the menu icon on the top right hand corner and then click on Get help and finally select How to enable the location services.");
        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();
}

关于如何绕过和阻止社交媒体阻止html5 geolocation的任何想法?

0 个答案:

没有答案