3

HTMLページで地理的な位置を取得しようとすると、次のエラーが発生します。エラーコード:2エラーメッセージ:最後のロケーションプロバイダーはここでは利用できなくなりました。これが私のコードです。

// onSuccess Callback
//  This method accepts a `Position` object, which contains
//  the current GPS coordinates
//
var onSuccess = function(position) {
   };

var HospitalsRecord = [];



//onError Callback receives a PositionError object
//
function onError(error) {
   alert('code: '    + error.code    + '\n' +
         'message: ' + error.message + '\n');
}

// Cordova is ready
//
function onDeviceReady() {
    navigator.geolocation.getCurrentPosition(onSuccess, onError, { maximumAge: Infinity, timeout: 15000, enableHighAccuracy: true });

}

// Wait for Cordova to load
//
document.addEventListener("deviceready", onDeviceReady, false);


</script>

なぜそれが起こっているのですか?

前もって感謝します

コビ

4

2 に答える 2

-1

このようにしてみてください..

<script type="text/javascript">

        // Wait for Cordova to load 

        document.addEventListener("deviceready", onDeviceReady, false);

        // Cordova is ready      

        function onDeviceReady() {

            navigator.geolocation.getCurrentPosition(onSuccess, onError);

        }

        // onSuccess Geolocation      

        function onSuccess(position) {

            var element = document.getElementById('geolocation');

            element.innerHTML = 'Latitude: ' + position.coords.latitude + '<br />' +

                            'Longitude: ' + position.coords.longitude + '<br />' +

                            'Altitude: ' + position.coords.altitude + '<br />' +

                            'Accuracy: ' + position.coords.accuracy + '<br />' +

                            'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '<br />' +

                            'Heading: ' + position.coords.heading + '<br />' +

                            'Speed: ' + position.coords.speed + '<br />' +

                            'Timestamp: ' + position.timestamp + '<br />';

        }

        // onError Callback receives a PositionError object     

        function onError(error) {

            alert('code: ' + error.code + '\n' +

              'message: ' + error.message + '\n');

        }

    </script>

詳細については..

これを試して

于 2013-01-15T08:49:50.590 に答える