2012-06-18 100 views
2

我试图让我的位置坐标与HTML5,但它每次都给我错误。phonegap HTML5地理位置

这是手机的差距Android项目

我用电话差距地理位置的文档,相同的代码的代码我有写。 并添加号召功能设备准备就绪()知道,如果这个代码运行

,这让我

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

希望建议我该做什么!

+0

这个问题可以帮助你找出问题:http://stackoverflow.com/questions/5407973/navigator-geolocation-getcurrentposition-throws-the-last-location-提供者 - 是 – Arnab

+0

它仍然不与我合作,没有什么变化,我启用了位置! –

回答

0

尽量选择enableHighAccuracy设置为true