Chrome IOS HTML5地理位置权限被拒绝

cha*_*had 9 html5 google-chrome ios w3c-geolocation

当尝试在ios的移动Chrome上使用HTML5地理定位API时,我的应用程序会抛出"权限被拒绝"错误,甚至没有提示共享我的位置.还有其他人遇到过这个问题吗?

PS.这发生在本地和heroku实例上.

这是我在文档就绪时运行的代码

    var displayCloseFoo = function(position) {
        var lat = position.coords.latitude;
        var lon = position.coords.longitude;

    };

    var displayError =  function(error) {
        var errors = {
            1: 'Permission denied',
            2: 'Position unavailable',
            3: 'Request timeout'
        };
        alert("Error: " + errors[error.code]);
    };

    var runGeo =  function(){
        if (navigator.geolocation) {
            var timeoutVal = 10 * 1000 * 1000;
            navigator.geolocation.getCurrentPosition(
                    displayCloseFoo,
                    displayError,
                    { enableHighAccuracy: true, timeout: timeoutVal, maximumAge: 0 }
            );
        }
        else {
            alert("Geolocation is not supported by this browser");
        }
    };
    runGeo();
Run Code Online (Sandbox Code Playgroud)

谢谢

cha*_*had 5

您必须明确允许 Mobile Chrome 在 ios 中使用定位服务。在 ios6 中,您可以通过转到 Settings->Privacy->Location Services 并将 Chrome 切换为 On 来实现此目的。