使用(navigator.geolocation)检测浏览器功能错误



我已经编写了一个脚本来检查我的浏览器是否具有功能。以下脚本正在产生错误:

<!DOCTYPE HTML>
<html>
    <head>
            <title id="title"> code Issues </title>
    </head>
    <body>      
            //=================== testing the feature detection method by using geolocation =======================//
            function geosuccess(position)
            {
                var cords = position.cords;
                var latitude = position.latitude;
                var longitude = postion.longitude;
                var message = "You're at " + latitude + ", " + longitude
                    alert(message);
            }
            function geoError(errorObj)
            {
                alert(errorObj.message);
            }
            if(typeof navigator.geolocation != "undefined")
            {
                console.log("inside geolocation");
                navigator.geolocation.getCurrentPosition(geoSuccess, geoError);
            }
            else
            {
                alert("thos page uses Geolocation and your browser doesn't support it");
            }

            //=================== End of testing the feature detection method by using geolocation =======================//

            </script>

    <h1>List Publishers Ltd.</h1>
    <div class="book">
        <h2>Sprout.</h2>
        <p>A book by J. Daniel Bedford</p>
        <a href="#">Read now.</a>
    </div>      
    </body>
</html>

如果我运行这个,我会得到一个错误,即geosuccessundefined

我试着调试这个脚本,我可以看到它无法检测到函数geoSuccess(position)

我希望我没有错过一个面向对象的概念,这个错误可能与浏览器有关。

首先,您的代码缺少一个打开的<script>标记,但我认为这只是一个错误。

其次,您的代码将函数定义为geosuccess,但将geoSuccess传递给getCurrentPosition。请检查您的代码中的案例是否匹配。

最新更新