《Compass(指南针)phonegap中文API(.docx》由会员分享,可在线阅读,更多相关《Compass(指南针)phonegap中文API(.docx(17页珍藏版)》请在三一文库上搜索。
1、Compass6旨南针)phonegap 中文 API(Commpass (指南针)获得该设备的方向指向。方法? compass.getCurrentHeading? compass.watchHeading? compass.clearWatch参数? compassSuccess? compassError? compassOptionscompass.getCurrentHeading获取当前罗盘航向。pass.getCurrentHeadin g(compassSuccess, compassError, compassOptions);说明它的措施,从0到指南针是一种传感器,检测到的
2、方向或标题,指出该设备。359.99度的标题。指南针返回标题使用compassSuccess 回调函数。支持的平台? Android? iPhone简单的例子function onSuccess(heading) alert( ;Heading:+ heading);charset =utf-8”function onError() alert( ;Error! );pass.getCurrentHeadin g(onSuccess, onError);完整的例子 Compass Example script type =text/javascript”src =phonegap.js scr
3、ipt type =text/javascriptcharset =utf-8/ Wait for PhoneGap to load/function onLoad() document.addEventListener(deviceready , onDeviceReady, false ); / PhoneGap is ready/function onDeviceReady() pass.getCurren tHeading(onSuccess, onError);/ onSuccess: Get the current heading/function onSuccess(headin
4、g) alert( Heading: + heading); / onError: Failed to get the heading/function onError() alert( onError! ); Example getCurrentHeading compass.watchHeading在定期间隔,获得指南针度标题。var watchlD =pass.watchHeading(com passSuccess, compassError, compassOptions);说明指南针是一种传感器,检测到的方向或标题,指出该设备。它的措施,从0到359.99度的标题。该compass
5、.watchHeading获取设备的当前间隔在例行标题。每次标题检索,headingSuccess回调函数被执行。通过指定的时间间隔以毫秒为单位的频率 参数在 compassOptions 对象。返回的手表ID引用引用指南针手表的时间问隔。这款手表ID可用于compass.clearWatch 停止看指南针。支持的平台? Android? iPhone简单的例子function onSuccess(heading) var element =document.getElementById(heading );element.innerHTML =Heading:+ heading;alert(
6、Error! );;var options= frequency: 3000 ;/Update every 3 secondsvar watchlD =pass.watchHeading(onS uccess, onError, options);完整的例子Compass Example script type =text/javascriptcharset =utf-8”src =phonegap.js script type =text/javascriptcharset =utf-8/ The watch id references the current watchHeadingvar
7、 watchlD = null/ Wait for PhoneGap to load/function onLoad() document.addEventListener(deviceready , onDeviceReady, false ); / PhoneGap is ready/function onDeviceReady() startWatch();/ Start watching the compass/function startWatch() / Update compass every 3 secondsvar options = frequency: 3000 ;wat
8、chID =pass.watchHeading(onS uccess, onError, options);/ Stop watching the compass/function stopWatch() if (watchID) pass.clearWatch(watchID);watchID =null ;/ onSuccess: Get the current heading/function onSuccess(heading) var element =document.getElementById( heading );element.innerHTML= Heading:+ he
9、ading;/ onError: Failed to get the heading/function onError() alert( onError! );Waiting forheading. buttononclick = startWatch(); StartWatching buttononclick = stopWatch(); StopWatching compass.clearWatch不看指南针手表引用ID参数。pass.clearWatch(watchID);? watchlD : 返回的 ID compass.watchHeading 支持的平台?机器人? iPhone
10、简单的例子var watchlD =pass.watchHeading(onSuccess, onError, options);/ . later on .pass.clearWatch(watchID);完整的例子 Compass Example script type =text/javascriptcharset =utf-8src =phonegap.js script type =text/javascriptcharset =utf-8/ The watch id references the current watchHeadingvar watchlD = null / Wa
11、it for PhoneGap to load/function onLoad() document.addEventListener(deviceready , onDeviceReady, false ); / PhoneGap is ready/function onDeviceReady() startWatch();/ Start watching the compass/function startWatch() / Update compass every 3 secondsvar options = frequency:3000 ;watchlD =pass.watchHead
12、ing(onS uccess, onError, options);/ Stop watching the compass /function stopWatch() if (watchID) pass.clear Watch(watchID);watchID =null/ onSuccess: Get the current heading /function onSuccess(heading) var element =document.getElementById( heading );element.innerHTML= Heading:+ heading;/ onError: Fa
13、iled to get the heading/function onError() alert( onError! );Waiting for heading. buttononclick = startWatch(); StartWatching buttononclick = stopWatch(); StopWatching compassSuccessonSuccess回调函数,提供了罗盘航向信息function (heading) / Do something?标题:标题度从0 - 359.99。在一个单一的时刻,时间的 (数)范例function onSuccess(heading) alert( Heading: + heading);compassError回调函数的OnError指南针功能。function ()/ /处理错误compassOptions一个可选的参数来定制罗盘检索。选项?频率:多久检索罗盘毫秒标题英寸(数目)(默认:100)