2015-11-10 25 views
0

我正在尝试使用Adobe在线构建来制作基本应用程序。我所拥有的是以下index.html,它应该可以获取地理位置并在应用视图中显示。但是,当我安装我无法看到任何东西。这是我上传到Adobe Online phonegap builder的唯一文件。当我尝试在设备上使用相机执行此操作时,它工作得很好。我应该添加任何配置文件等?使用Adobe在线构建Phonegap应用程序

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

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

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

    // device APIs are available 
    // 
    function onDeviceReady() { 
     navigator.geolocation.getCurrentPosition(onSuccess, onError); 
    } 

    // 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: '   + 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

我只是在telerik平台上运行它,它工作正常,但是当我为Android构建它时,它不适用于我的手机。 – Amir

+0

请发布您的'config.xml' – JesseMonroy650

+0

我没有一个Jesse,它需要在Android中使用GPS? – Amir

回答

0

我使用Telerik平台得到了这个工作。如果您需要复制,则样本和步骤如下。

1-拷贝代码到您的index.html

<!DOCTYPE html> 
<!-- 
    Licensed to the Apache Software Foundation (ASF) under one 
    or more contributor license agreements. See the NOTICE file 
    distributed with this work for additional information 
    regarding copyright ownership. The ASF licenses this file 
    to you under the Apache License, Version 2.0 (the 
    "License"); you may not use this file except in compliance 
    with the License. You may obtain a copy of the License at 

    http://www.apache.org/licenses/LICENSE-2.0 

    Unless required by applicable law or agreed to in writing, 
    software distributed under the License is distributed on an 
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
    KIND, either express or implied. See the License for the 
    specific language governing permissions and limitations 
    under the License. 
--> 
<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" /> 
     <link rel="stylesheet" type="text/css" href="css/index.css" /> 
     <title>Hello World!</title> 
    </head> 
    <body> 
     <div class="app"> 
      <h1>Apache Cordova</h1> 
      <div id="deviceready" class="blink"> 
       <p class="event listening">Connecting to Device</p> 
       <p class="event received">Device is Ready</p> 
      </div> 
     </div> 
     <script type="text/javascript" src="cordova.js"></script> 
     <script type="text/javascript" src="js/index.js"></script> 
     <script type="text/javascript"> 
      app.initialize(); 
     </script> 
      <body> 
    <p id="geolocation">Finding geolocation...</p> 
    </body> 
    </body> 
</html> 

2 - 复制此到您的index.js:

var app = { 
    // Application Constructor 
    initialize: function() { 
     this.bindEvents(); 
    }, 
    // Bind Event Listeners 
    // 
    // Bind any events that are required on startup. Common events are: 
    // 'load', 'deviceready', 'offline', and 'online'. 
    bindEvents: function() { 
     document.addEventListener('deviceready', this.onDeviceReady, false); 
    }, 
    // deviceready Event Handler 
    // 
    // The scope of 'this' is the event. In order to call the 'receivedEvent' 
    // function, we must explicity call 'app.receivedEvent(...);' 
    onDeviceReady: function() { 
     app.receivedEvent('deviceready'); 
     navigator.splashscreen.hide(); 
     navigator.geolocation.getCurrentPosition(onSuccess, onError); 
      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-Amir: '   + position.timestamp     + '<br />'; 
    } 

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

    }, 
    // Update DOM on a Received Event 
    receivedEvent: function(id) { 
     var parentElement = document.getElementById(id); 
     var listeningElement = parentElement.querySelector('.listening'); 
     var receivedElement = parentElement.querySelector('.received'); 

     listeningElement.setAttribute('style', 'display:none;'); 
     receivedElement.setAttribute('style', 'display:block;'); 

     console.log('Received Event: ' + id); 
    } 
}; 

3-打开右侧的属性。选中Android权限下的访问精细/粗略位置框。 4-构建设备并在android上运行。

相关问题