Compass(指南针)phonegap中文API(

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

Commpass(指南针)获得该设备的方向指向。方法compass.getCurrentHeadingcompass.watchHeadingcompass.clearWatch参数compassSuccesscompassErrorcompassOptionscompass.getCurrentHeading获取当前罗盘航向。navigator.compass.getCurrentHeading(compassSuccess,compassError,compassOptions);说明指南针是一种传感器,检测到的方向或标题,指出该设备。它的措施,从0到359.99度的标题。指南针返回标题使用compassSuccess回调函数。支持的平台AndroidiPhone简单的例子functiononSuccess(heading){alert('Heading:'+heading);};functiononError(){alert('onError!');};navigator.compass.getCurrentHeading(onSuccess,onError);完整的例子!DOCTYPEHTMLPUBLIC-//W3C//DTDHTML4.01//EN=text/javascriptcharset=utf-8src=phonegap.js/scriptscripttype=text/javascriptcharset=utf-8//WaitforPhoneGaptoload//functiononLoad(){document.addEventListener(deviceready,onDeviceReady,false);}//PhoneGapisready//functiononDeviceReady(){navigator.compass.getCurrentHeading(onSuccess,onError);}//onSuccess:Getthecurrentheading//functiononSuccess(heading){alert('Heading:'+heading);}//onError:Failedtogettheheading//functiononError(){alert('onError!');}/script/headbodyonload=onLoad()h1Example/h1pgetCurrentHeading/p/body/htmlcompass.watchHeading在定期间隔,获得指南针度标题。varwatchID=navigator.compass.watchHeading(compassSuccess,compassError,[compassOptions]);说明指南针是一种传感器,检测到的方向或标题,指出该设备。它的措施,从0到359.99度的标题。该compass.watchHeading获取设备的当前间隔在例行标题。每次标题检索,headingSuccess回调函数被执行。通过指定的时间间隔以毫秒为单位的频率参数在compassOptions对象。返回的手表ID引用引用指南针手表的时间间隔。这款手表ID可用于compass.clearWatch停止看指南针。支持的平台AndroidiPhone简单的例子functiononSuccess(heading){varelement=document.getElementById('heading');element.innerHTML='Heading:'+heading;};functiononError(){alert('onError!');};varoptions={frequency:3000};//Updateevery3secondsvarwatchID=navigator.compass.watchHeading(onSuccess,onError,options);完整的例子!DOCTYPEHTMLPUBLIC-//W3C//DTDHTML4.01//EN=text/javascriptcharset=utf-8src=phonegap.js/scriptscripttype=text/javascriptcharset=utf-8//Thewatchidreferencesthecurrent`watchHeading`varwatchID=null;//WaitforPhoneGaptoload//functiononLoad(){document.addEventListener(deviceready,onDeviceReady,false);}//PhoneGapisready//functiononDeviceReady(){startWatch();}//Startwatchingthecompass//functionstartWatch(){//Updatecompassevery3secondsvaroptions={frequency:3000};watchID=navigator.compass.watchHeading(onSuccess,onError,options);}//Stopwatchingthecompass//functionstopWatch(){if(watchID){navigator.compass.clearWatch(watchID);watchID=null;}}//onSuccess:Getthecurrentheading//functiononSuccess(heading){varelement=document.getElementById('heading');element.innerHTML='Heading:'+heading;}//onError:Failedtogettheheading//functiononError(){alert('onError!');}/script/headbodyonload=onLoad()divid=headingWaitingforheading.../divbuttononclick=startWatch();StartWatching/buttonbuttononclick=stopWatch();StopWatching/button/body/htmlcompass.clearWatch不看指南针手表引用ID参数。navigator.compass.clearWatch(watchID);watchID:返回的IDcompass.watchHeading。支持的平台机器人iPhone简单的例子varwatchID=navigator.compass.watchHeading(onSuccess,onError,options);//...lateron...navigator.compass.clearWatch(watchID);完整的例子!DOCTYPEHTMLPUBLIC-//W3C//DTDHTML4.01//EN=text/javascriptcharset=utf-8src=phonegap.js/scriptscripttype=text/javascriptcharset=utf-8//Thewatchidreferencesthecurrent`watchHeading`varwatchID=null;//WaitforPhoneGaptoload//functiononLoad(){document.addEventListener(deviceready,onDeviceReady,false);}//PhoneGapisready//functiononDeviceReady(){startWatch();}//Startwatchingthecompass//functionstartWatch(){//Updatecompassevery3secondsvaroptions={frequency:3000};watchID=navigator.compass.watchHeading(onSuccess,onError,options);}//Stopwatchingthecompass//functionstopWatch(){if(watchID){navigator.compass.clearWatch(watchID);watchID=null;}}//onSuccess:Getthecurrentheading//functiononSuccess(heading){varelement=document.getElementById('heading');element.innerHTML='Heading:'+heading;}//onError:Failedtogettheheading//functiononError(){alert('onError!');}/script/headbodyonload=onLoad()divid=headingWaitingforheading.../divbuttononclick=startWatch();StartWatching/buttonbuttononclick=stopWatch();StopWatching/button/body/htmlcompassSuccessonSuccess回调函数,提供了罗盘航向信息。function(heading){//Dosomething}参数标题:标题度从0-359.99。在一个单一的时刻,时间的(数)范例functiononSuccess(heading){alert('Heading:'+heading);};compassError回调函数的OnError指南针功能。function(){//处理错误}compassOptions一个可选的参数来定制罗盘检索。选项频率:多久检索罗盘毫秒标题英寸(数目)(默认:100)

1 / 8
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功