Commpass(指南针)获得该设备的方向指向。方法compass.getCurrentHeadingcompass.watchHeadingcompass.clearWatch参数compassSuccesscompassErrorcompassOptionscompass.getCurrentHeading获取当前罗盘航向。navigator.compass.getCurrentHeading(compassSuccess,compassError,compassOptions);说明指南针是一种传感器,检测到的方向或标题,指出该设备。它的措施,从0到359.99度的标题。指南针返回标题使用compassSuccess回调函数。支持的平台AndroidiPhone简单的例子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停止看指南针。支持的平台AndroidiPhone简单的例子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)