phonegap-API

上传人:hs****ma 文档编号:509283182 上传时间:2023-12-03 格式:DOC 页数:209 大小:642.21KB
返回 下载 相关 举报
phonegap-API_第1页
第1页 / 共209页
phonegap-API_第2页
第2页 / 共209页
phonegap-API_第3页
第3页 / 共209页
phonegap-API_第4页
第4页 / 共209页
phonegap-API_第5页
第5页 / 共209页
点击查看更多>>
资源描述

《phonegap-API》由会员分享,可在线阅读,更多相关《phonegap-API(209页珍藏版)》请在金锄头文库上搜索。

1、目录Accelerometer1Camera11Capture18Compass35Connection48Contacts50Device76Events84File107Geolocation139Media154Notification183Storage192Accelerometer“采集设备在x、y、z方向上的动作。方法: accelerometer.getCurrentAcceleration accelerometer.watchAcceleration accelerometer.clearWatch参数: accelerometerSuccess accelerometer

2、Error accelerometerOptions对象(只读): Accelerationaccelerometer.getCurrentAcceleration返回当前沿x、y和z方向的加速度。复制navigator.accelerometer.getCurrentAcceleration(accelerometerSuccess, accelerometerError);说明:加速计是检测设备在当前方向上所做相对运动变化(增、减量)的运动传感器。加速计可以检测沿X、Y和Z轴的三维运动。加速度数据通过accelerometerSuccess回调函数返回。支持的平台: Android Bla

3、ckBerry WebWorks (OS 5.0或更高版本) iPhone简单的范例:复制function onSuccess(acceleration) alert(Acceleration X: + acceleration.x + n +Acceleration Y: + acceleration.y + n +Acceleration Z: + acceleration.z + n +Timestamp: + acceleration.timestamp + n);function onError() alert(onError!);navigator.accelerometer.ge

4、tCurrentAcceleration(onSuccess, onError);完整的范例:复制Acceleration Example/ 等待加载PhoneGap document.addEventListener(deviceready, onDeviceReady, false); / PhoneGap加载完毕function onDeviceReady() navigator.accelerometer.getCurrentAcceleration(onSuccess, onError);/ onSuccess: 返回当前加速度数据的快照function onSuccess(acce

5、leration) alert(Acceleration X: + acceleration.x + n +Acceleration Y: + acceleration.y + n +Acceleration Z: + acceleration.z + n +Timestamp: + acceleration.timestamp + n);/ onError: 返回加速度数据失败function onError() alert(onError!);ExamplegetCurrentAccelerationiPhone的特异情况: iPhone没有获取在任何给定点当前加速度数据的概念。 你必须通

6、过给定时间间隔查看加速度并获得数据。 因此,getCurrentAcceleration函数会返回从phoneGap watchAccelerometer调用开始后的最近一个返回值。accelerometer.watchAcceleration在固定的时间间隔获取沿x、y和z轴的加速度。复制var watchID = navigator.accelerometer.watchAcceleration(accelerometerSuccess,accelerometerError,accelerometerOptions);说明:加速计是检测设备在当前方向上所做相对运动变化(增、减量)的动作传感

7、器。加速计可以检测沿X、Y和Z轴的三维运动。accelerometer.watchAcceleration每隔固定时间就获取一次设备的当前加速度。每次取得加速度后,accelerometerSuccess回调函数会被执行。通过acceleratorOptions对象的frequency参数可以设定以毫秒为单位的时间间隔。返回的watch id是加速度计监视周期的引用,可以通过accelerometer.clearWatch调用该watch ID以停止对加速度计的监视。支持的平台: Android BlackBerry WebWorks (OS 5.0或更高版本) iPhone简单的范例:复制f

8、unction onSuccess(acceleration) alert(Acceleration X: + acceleration.x + n +Acceleration Y: + acceleration.y + n +Acceleration Z: + acceleration.z + n +Timestamp: + acceleration.timestamp + n);function onError() alert(onError!);var options = frequency: 3000 ; / 每隔3秒更新一次var watchID = navigator.accele

9、rometer.watchAcceleration(onSuccess, onError, options);完整的范例:复制Acceleration Example/ watch id 是当前“watchAcceleration”的引用var watchID = null;/ 等待加载PhoneGapdocument.addEventListener(deviceready, onDeviceReady, false);/ PhoneGap加载完毕function onDeviceReady() startWatch();/ 开始监视加速度function startWatch() / 每隔

10、3秒钟更新一次加速度数据var options = frequency: 3000 ;watchID = navigator.accelerometer.watchAcceleration(onSuccess, onError, options);/ 停止监视加速度function stopWatch() if (watchID) navigator.accelerometer.clearWatch(watchID);watchID = null;/ onSuccess: 获取当前加速度数据的快照function onSuccess(acceleration) var element = do

11、cument.getElementById(accelerometer);element.innerHTML = Acceleration X: + acceleration.x + +Acceleration Y: + acceleration.y + +Acceleration Z: + acceleration.z + +Timestamp: + acceleration.timestamp + ;/ onError: 获取加速度失败function onError() alert(onError!);Waiting for accelerometer.iPhone的特异情况: 在请求的

12、时间间隔,PhoneGap将调用success回调指向的函数,并传递加速度计数据。 不过,PhoneGap将对设备的请求间隔时间限制为最小40ms,最大1000ms。 例如,如果你设定每隔3秒(3000毫秒)请求一次,PhoneGap仍然每隔1秒请求一次设备,但是每隔3秒才调用一次success回调函数。accelerometer.clearWatch停止watch ID参数指向的加速度监视。复制navigator.accelerometer.clearWatch(watchID); watchID:由accelerometer.watchAcceleration返回的引用标识ID。支持的平台: Android BlackBerry WebWorks (OS 5.0或更高版本) iPhone简单的范例:复制var watchID = navigator.accelerometer.watchAcceleration(onSuccess, onError

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 建筑/环境 > 施工组织

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号