【问题标题】:phonegap HTML5 geolocationphonegap HTML5 地理位置
【发布时间】:2012-06-18 17:35:49
【问题描述】:

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

希望建议我该怎么做!

【问题讨论】:

标签: android cordova geolocation


【解决方案1】:

尝试将选项 enableHighAccuracy 设置为 true

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-16
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多