0

我尝试使用 html5 对 WP8 进行跟踪,以获取我的位置并将其显示为代码,但没问题

    <script type="text/javascript">
    var watchID = 0;

    function startLocationTracking() {
        if (navigator.geolocation) {
            var messagedialogpopup = new Windows.UI.Popups.MessageDialog
                    ("Your phone supports GeoLocation");
            messagedialogpopup.showAsync();
            watchID = navigator.geolocation.watchPosition(showCurrentLocation, errorHandler, { enableHighAccuracy: true });
        } else {
            var messagedialogpopup = new Windows.UI.Popups.MessageDialog
                    ("Your phone does not support GeoLocation.");
            messagedialogpopup.showAsync();
        }
    }

    function showCurrentLocation(position) {
        document.getElementById("mylocation").innerHTML = "Tracking your position --> Current Latitude : " + position.coords.latitude + " , Longitude : " + position.coords.longitude;
    }

    function errorHandler(error) {
        var messagedialogpopup = new Windows.UI.Popups.MessageDialog
                    ("Error while retrieving current position. Error code: " + error.code + ",Message: " + error.message);

    }

    function stopLocationTracking() {
        if (watchID > 0) {
            navigator.geolocation.clearWatch(watchID);
            var messagedialogpopup = new Windows.UI.Popups.MessageDialog
                    ("Stopped Tracking Location");
            messagedialogpopup.showAsync();
        }
    }

    </script>

</head>
<body class="phone">

    <div id="main">

        <input type="button" value="Start Tracking Me" onclick="startLocationTracking()" />
        <input type="button" value="Stop Tracking Me" onclick="stopLocationTracking()" />
        <br />
        <div id="mylocation"></div>
    </div>

</body>
</html>

它显示此屏幕,但问题未显示结果。它应该显示如下内容:跟踪您的位置->当前纬度:34.8346549,经度:10.7518134 在此处输入图像描述

4

0 回答 0