phonegap HTML5地理定位

时间:2012-06-18 17:35:49

标签: android cordova geolocation

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

这是我写给手机间隙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

希望建议我该做什么!!

1 个答案:

答案 0 :(得分:0)

尝试将选项enableHighAccuracy设置为true