跟踪Windows Phone中的位置

时间:2014-08-23 12:28:55

标签: javascript html5 windows-phone-8.1 bing-maps w3c-geolocation

我尝试使用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>

显示此屏幕但问题未显示结果。 它假设显示这样的事情: 追踪你的位置 - &gt;当前纬度:34.8346549,经度:10.7518134 enter image description here

0 个答案:

没有答案