2012-11-07 51 views
0

我創建了Adroid應用程序,我在其中檢查手機的位置。我開始模擬器安裝應用程序,每次我想檢查它失敗。是模擬器的問題(因爲它不是一個真正的手機)或我沒有做到這一點。build.phonegap.com版本的Android應用程序

<!DOCTYPE html> 
<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
     <meta name="format-detection" content="telephone=no" /> 
     <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" /> 
       <title>Hello World</title> 
     <script type="text/javascript" src="cordova-2.1.0.js"></script> 
     <script text="text/javascript"> 
     function startUp(){ 
      document.getElementById("H1").innerHTML = "Checking your location..."; 
      document.addEventListener("deviceready", onDeviceReady, false) 
     } 
     function onDeviceReady() { 
     navigator.geolocation.getCurrentPosition(onSuccess, onError); 
    } 

    // onSuccess Geolocation 
    // 
    function onSuccess(position) { 
     var element = document.getElementById('location'); 
     element.innerHTML = 'Latitude: '   + position.coords.latitude    + '<br />' + 
          'Longitude: '   + position.coords.longitude    + '<br />' + 
          'Altitude: '   + position.coords.altitude    + '<br />'; 
          document.getElementById("H1").innerHTML = ""; 
    } 

    // onError Callback receives a PositionError object 
    // 
    function onError(error) { 
     document.getElementById("H1").innerHTML = "Fail to check your location."; 
    } 

     </script> 
    </head> 
    <body style="margin:0px;" onload="startUp()" bgcolor="#000"> 
     <div class="app" style="background-color:#4D4D4D"> 
      <font color="#FF9900" size="2"><h1 id="H1" style="font-family:courier new;"></h1></font> 
      <p id="location"></p> 
     </div> 



    </body> 
</html> 

HTML5文件和config.xml中

<?xml version="1.0" encoding="UTF-8" ?> 
    <widget xmlns = "http://www.w3.org/ns/widgets" 
     xmlns:gap = "http://phonegap.com/ns/1.0" 
     id  = "com.park.manager" 
     versionCode="10" 
     version = "0.1.9"> 
    <name>ParkingManager</name> 
    <description> 
     A system, which manages parking side areas. 
    </description> 
    <author href="" email=""> 
     Parking Side Manager Team 
    </author> 
    <preference name="phonegap-version" value="2.1.0" /> 
    <preference name="orientation" value="landscape" /> 
    <preference name="target-device" value="universal" /> 
    <preference name="fullscreen" value="true" /> 
    <preference name="android-installLocation" value="auto" /> 
    <icon src="icon.png" /> 
    <gap:splash src="splash.png" /> 
    <feature name="http://api.phonegap.com/1.0/geolocation"/> 
    <feature name="http://api.phonegap.com/1.0/network"/> 

</widget> 

回答

0

確保在您的清單XML您添加權限粗,細位置。

手機差距有其優勢,但它不會解決您的一些主要問題,例如必須手動完成清單。如果您在知道如何添加這些權限之前使用java創建應用程序。如果不用來檢查如何去做。 permissions

除了您的cordova geolaction調用是正確的,我已經在他們的例子中使用過它。

0

其模擬器,你需要一個真正的手機,因爲模擬器是一個痛苦的,你知道什麼才能正確工作。你的Javascript和html都很好。

相關問題