了解汽车何时进行机动

问题描述 投票:0回答:1

我需要查明汽车是否会进行 45 度之类的机动。

我尝试使用 GPS 的位置和航向以避免磁力计 - 陀螺仪 - 加速度计,因为它们似乎使用起来有点棘手。

我不知道你建议我使用什么,实现这一目标的最佳方法是什么?

我正在尝试开始使用这个位置标题来确定它是否旋转,但是当我旋转模拟器时,我得到了大约 0.1 度的差异,我不知道为什么我旋转了近 45 度。

这是我的代码:

import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';

class Geo extends StatefulWidget {
  @override
  _GeoState createState() => _GeoState();
}

class _GeoState extends State<Geo> {
  double? _previousHeading;
  double? _currentHeading;
  double? _latitude;
  double? _longitude;

  @override
  void initState() {
    super.initState();
    _getCurrentLocation();
  }

  Future<void> _getCurrentLocation() async {
    try {
      late LocationSettings locationSettings;

      locationSettings = AndroidSettings(
        accuracy: LocationAccuracy.bestForNavigation,
        forceLocationManager: true,
        intervalDuration: const Duration(milliseconds: 100),
      );

      Stream<Position> positionStream =
          Geolocator.getPositionStream(locationSettings: locationSettings);

      positionStream.listen((Position position) {
        setState(() {
          _latitude = position.latitude;
          _longitude = position.longitude;
          _currentHeading = position.heading;
        });

        print('Latitude: $_latitude, Longitude: $_longitude');
        print('Heading: $_currentHeading degrees');
      });
    } catch (e) {
      print('Error: $e');
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Location and Heading Checker'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            if (_latitude != null && _longitude != null)
              Text(
                'Latitude: $_latitude, Longitude: $_longitude',
                style: TextStyle(fontSize: 18),
              ),
            SizedBox(height: 20),
            if (_currentHeading != null)
              Text(
                'Heading: ${_currentHeading!.toStringAsFixed(2)} degrees',
                style: TextStyle(fontSize: 18),
              ),
            SizedBox(height: 20),
            Text(
              'Check the console for location and heading updates.',
              textAlign: TextAlign.center,
            ),
          ],
        ),
      ),
    );
  }
}

Kotlin 的答案也可以接受,我可以做一个平台频道就可以了。

提前致谢。

android flutter flutter-dependencies
1个回答
0
投票

要从 GPS 系统获取方位,设备需要沿着路径移动。确保您正在移动设备,然后沿所遵循的路径进行 90 度转弯。

我还会检查位置。速度以过滤掉 GPS 未检测到任何移动的修复。

© www.soinside.com 2019 - 2024. All rights reserved.