1

我正在尝试使用 HTML5 获取我的位置坐标,但每次都会出错。

这是我写给phone gap android项目的代码

我在电话间隙地理位置的文档中使用了相同的代码。并添加对函数 device-ready() 的调用以了解此代码是否正在运行

它给了我

error 2 : messege 2 :    the last location provider was disabled 

这是我用来在 android 设备上获取我的位置的代码!

<!DOCTYPE html>
<html>
  <head>
    <title>Device Properties Example</title>

    <script type="text/javascript" charset="utf-8" src="phonegap-1.4.1.js"></script>
    <script type="text/javascript" charset="utf-8">

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

    var watchID = null;

    // PhoneGap is ready
    //
    function onDeviceReady() {
    // Update every 3 seconds
    var options = { frequency: 3000 };
    watchID = navigator.geolocation.watchPosition(onSuccess, onError, options);
}

// onSuccess Geolocation
//
function onSuccess(position) {
    var element = document.getElementById('geolocation');
    element.innerHTML = 'Latitude: '  + position.coords.latitude      + '<br />' +
                        'Longitude: ' + position.coords.longitude     + '<br />' +
                        '<hr />'      + element.innerHTML;

//alert("the lang is : "+position.coords.latitude);
document.write("the lang is : "+position.coords.latitude);

    }

// clear the watch that was started earlier
// 
function clearWatch() {
    if (watchID != null) {
        navigator.geolocation.clearWatch(watchID);
        watchID = null;
    }
}

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

</script>
  </head>
  <body>


    <p id="geolocation">Watching geolocation...</p><br>
<button onclick="onDeviceReady();">onDeviceReady()</button>   <br>
<button onclick="clearWatch();">Clear Watch</button>   <br>

    <a href="index2.html"> index 2 </a>
  </body>
</html>

我从这里http://docs.phonegap.com/en/1.7.0/cordova_geolocation_geolocation.md.html#Geolocation得到了这个教程!

希望建议我该怎么做!

4

1 回答 1

0

尝试将选项 enableHighAccuracy 设置为 true

于 2013-01-30T09:27:54.057 回答