打开studio在左侧列表中找到config.xml文件,双击打开,选择插件选项勾选cordova-plugin-device-orientation文件,并在权限选项中选择相关权限。最后保存文件。

定位装置

summer框架中的联系可以使用cordova插件(cordova-plugin-device-orientation),主要功能包含:

1、获取罗盘信息

  1. function onSuccess(heading) {
  2. alert('Heading: ' + heading.magneticHeading); //磁航向
  3. };
  4. function onError(error) {
  5. alert('CompassError: ' + error.code);
  6. };
  7. navigator.compass.getCurrentHeading(onSuccess, onError); //获取罗盘信息

2、查看罗盘信息

  1. function onSuccess(heading) {
  2. var element = document.getElementById('heading');
  3. element.innerHTML = 'Heading: ' + heading.magneticHeading; //磁航向
  4. };
  5. function onError(compassError) {
  6. alert('Compass error: ' + compassError.code);
  7. };
  8. var options = {
  9. frequency: 3000 // Update every 3 seconds
  10. };
  11. watchID = navigator.compass.watchHeading(onSuccess, onError, options);//查看罗盘信息

3、清除罗盘信息

  1. navigator.compass.clearWatch(watchID);//清除罗盘信息

用例github下载地

更多参见

文档更新时间: 2018-01-15 13:58