2012-02-09 102 views
0

我嘗試在phonegap平臺上使用Android模擬器上的地理位置獲取座標。但它似乎不起作用。代碼應該是正確的,我在清單中添加權限,使用高清標籤,我該如何解決這個問題?謝謝 !android phonegap地理位置模擬器

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

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

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

    // PhoneGap is ready 
    // 
    function onDeviceReady() { 
     navigator.geolocation.getCurrentPosition(onSuccess, onError,{ enableHighAccuracy: true }); 
    } 

    // 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: '   + new Date(position.timestamp)   + '<br />'; 
    } 

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

    </script> 
    </head> 
    <body> 
    <p id="geolocation">Finding geolocation...</p> 
    </body> 
</html> 
+0

在模擬器中設置地理位置如下,在eclipse中轉到DDMS並選擇模擬器設置的經度,經度enter image description here – Arivu 2013-06-25 10:47:01

回答

1

您是否在模擬器中設置了位置?

e.g:

$ telnet localhost 5554 
$ geo fix -4.2 55.85