web-dev-qa-db-ja.com

geoLocation.GetCurrentPositionは常にIE 11

以下のスクリプトはFireFoxとChromeで正常に機能しますが、Internet Explorer 11では常に失敗します(POSITION_UNAVAILABLEを使用)。

位置の要求を許可するようにブラウザーを設定しました。許可を要求するときにブラウザーが表示するプロンプトに同意します。

私が最後に実験した数ヶ月前に、これがうまく機能したことはほぼ確実です。 IEの設定に関して、何が欠けている可能性がありますか?

<script type="text/javascript">
    $(document).ready(function () {
        if (Modernizr.geolocation)
        {
            navigator.geolocation.getCurrentPosition(positionSuccess, positionError, { enableHighAccuracy: true, maximumAge: 60000, timeout: 10000 })
        }
        else
        {
            $("#GeoError").html("Unable to retrieve current position.")
        }
    });

    function positionSuccess(position)
    {
        $("#Latitude").val(position.coords.latitude);
        $("#Longitude").val(position.coords.longitude);
    }

    function positionError(error)
    {
        var message = "";

        // Check for known errors
        switch (error.code) {
            case error.PERMISSION_DENIED:
                message = "This website does not have your permission to use the Geolocation API";
                break;
            case error.POSITION_UNAVAILABLE:
                message = "Your current position could not be determined.";
                break;
            case error.PERMISSION_DENIED_TIMEOUT:
                message = "Your current position could not be determined within the specified timeout period.";
                break;
        }

        // If it's an unknown error, build a message that includes 
        // information that helps identify the situation, so that 
        // the error handler can be updated.
        if (message == "") {
            var strErrorCode = error.code.toString();
            message = "Your position could not be determined due to " +
                      "an unknown error (Code: " + strErrorCode + ").";
        }

        $("#GeoError").html(message)
    }
</script>

また、IE11で http://html5demos.com/geo を試してみると、同じエラーが発生します。FireFoxとChromeの両方が正常に機能します。

15
Paul Marangoni

位置情報サービスを有効にしますか?

同じ問題が発生しました。Windows2016で位置情報サービスを有効にした後に機能しました。

このページは、Windows 10で位置情報サービスを有効にする方法を示しています

2
cocoa

IE11でのみ同じ問題が発生しました。それを機能させるには、enableHighAccuracyをfalseに設定する必要がありました。私がそれをしたらIEは期待通りに機能しました。

1
Ben Cameron

[インターネットオプション]で、[プライバシー]タブをクリックします。 [ウェブサイトに物理的な場所のリクエストを許可しない]チェックボックスをオフにして、[OK]をクリックします。

これらの変更を行った後、 http://html5demos.com/geo が機能しました。当初はそうではありませんでした。

0
Roman Canlas