搜索插件、代码仓与 APP 分类

插件详情v0.1.1

flutter_sensor_compass

一个用于获取设备相对于磁北方向的方位角(以度为单位)的插件。

近 30 天下载
27
喜欢数
3
Pub 分数
40

安装插件

flutter pub add flutter_sensor_compass

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

flutter_sensor_compass 包提供了一种简单的方法来访问设备的指南针传感器,可实时提供相对于磁北的方向数据(以度为单位)。它使应用程序能够检测设备的方向,非常适合用于导航、增强现实和基于位置的服务。该插件通过利用设备内置的磁力计工作,并专为无缝集成到 Flutter 应用程序而设计。它支持后台更新,并在极少配置的情况下提供准确的读数。开发者可以轻松订阅方向变化并相应地进行响应。

适合场景

  • 导航应用
  • 增强现实体验
  • 基于位置的游戏
  • 户外活动追踪
  • 地图方向

主要特点

  • 实时指南针数据
  • 磁北方向
  • 背景传感器更新
  • 简单 API 集成
  • 跨平台支持

适合对象

  • 开发导航工具的开发者
  • 需要设备方向感应的应用程序
  • AR和VR应用
  • 健身和户外追踪应用

使用建议

  • 需要带有磁力计的设备
  • 可能需要校准以确保准确性
  • 设备无传感器时受限
  • 由于持续轮询导致的电池使用
  • 准确性受附近磁干扰影响

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

flutter_sensor_compass

A plugin to get the orientation of the device (in degrees) relative to the magnetic north.

Installation

First add the plugin in your project. Copy the following line below dependencies in your pubspec.yaml file.

dependencies:
     ...
    flutter_sensor_compass: ^0.1.1

Then you need to import the dependency.

import 'package:flutter_sensor_compass/flutter_sensor_compass.dart';
iOS only

You need to add the following key-value pair into your Info.plist file inside the ios/Runner folder in your project.

<key>NSMotionUsageDescription</key>
<string>A reason to get the permission</string>

How to use

You can check if the device is capable of using the compass.

bool isAvailable = await Compass().isCompassAvailable();

Then you can register a new listener for the compass updates.

_compassSubscription =
        Compass().compassUpdates(interval: Duration(milliseconds: 200)).listen((value) {
      setState(() {
        _degrees = value;
      });
    });

Remember to cancel your StreamSubscriptions after you are done with the compass updates.

_compassSubscription.cancel();

所属分类

依赖

依赖清单 2 项

源码仓库

使用此插件的项目

暂无相关数据。