我无法在华为驱动程序中使用 GPS

如何解决我无法在华为驱动程序中使用 GPS

我有时会出现一个问题,当启用 GPS 时,在运行应用程序之前“没有任何反应”下一行无法执行 示例:

  _loadPosition() async {
    print('Are u here');  // it shows
    Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.bestForNavigation)
        .then((Position _getPosition) {
      setState(() {
        _myPosition = LatLng(_getPosition.latitude,_getPosition.longitude);
        CameraPosition cameraPosition =
            new CameraPosition(target: _myPosition,zoom: 16);
        _googleMapController
            .animateCamera(CameraUpdate.newCameraPosition(cameraPosition));
      });
    }).catchError((e) {
      print(e);
    });
    print('Any thing'); // it's not show
  }

手机是华为y9

文件 pubspec.yaml

name: test
description: A new Flutter project.

# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots,like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number,respectively.
# In Android,build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS,build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1

environment:
  sdk: ">=2.12.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations: # Add this line
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2
  firebase_core: ^1.2.0
  firebase_auth: ^1.2.0
#  firebase_storage: ^8.1.0
  firebase_database: ^7.0.0
  libphonenumber: ^2.0.0
  google_maps_flutter: ^2.0.5
  geolocator: ^7.0.3
  http: ^0.13.3
  provider: ^5.0.0
  flutter_typeahead: ^3.1.3
  flutter_polyline_points: ^1.0.0
  flutter_inner_drawer: ^1.0.0+1
  lottie: ^1.0.1
  flutter_geofire: ^2.0.0
  google_fonts: ^2.1.0
  easy_localization: ^3.0.0
  flutter_svg: ^0.22.0
  connectivity: ^3.0.6
  flutter_phone_direct_caller: ^2.0.0

dev_dependencies:
  flutter_test:
    sdk: flutter

# For information on the generic Dart part of this file,see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application,so that you can use the icons in
  # the material Icons class.
  uses-material-design: true
  assets:
    - assets/translations/
  # To add assets to your application,add an assets section,like this:
    - assets/images/
    - assets/json_assets/
  #   - images/a_dot_ham.jpeg

  # An image asset can refer to one or more resolution-specific "variants",see
  # https://flutter.dev/assets-and-images/#resolution-aware.

  # For details regarding adding assets from package dependencies,see
  # https://flutter.dev/assets-and-images/#from-packages

  # To add custom fonts to your application,add a fonts section here,# in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name,and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,# see https://flutter.dev/custom-fonts/#from-packages

dart 文件

import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_phone_direct_caller/flutter_phone_direct_caller.dart';

import 'package:geolocator/geolocator.dart';

import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart' as Marker;

import 'package:lottie/lottie.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:provider/provider.dart';
import 'package:transfer/Models/Trip.dart';
import 'package:transfer/Widgets/Button.dart';
import 'package:transfer/Widgets/NoInternet.dart';
import 'package:transfer/providers/ConnectivityProviders.dart';
import 'package:transfer/providers/FireBaseDB.dart';

class MainScreen extends StatefulWidget {
  static const String screenID = "MainScreen";

  @override
  _MainScreenState createState() => _MainScreenState();
}

class _MainScreenState extends State<MainScreen> with TickerProviderStateMixin {
  Completer<GoogleMapController> _controller = Completer();
  late AnimationController _controllerAnimation;
  static final CameraPosition _cameraPosition =
      CameraPosition(target: LatLng(30.3697373,30.521441),zoom: 14.47);
  List<LatLng> pLine = [];
  Set<Polyline> polylineSet = {};
  late GoogleMapController _googleMapController;
  MapType _currentMapType = MapType.normal;
  double bottomPosition = 0;

  bool _findPage = false;
  Map<MarkerId,Marker.Marker> _markersAll = <MarkerId,Marker.Marker>{};
  late LatLng _cameraMovePosition;
  late LatLng _myPosition = LatLng(30.3697373,30.521441);
  late FireBaseDBProvider firebasedb;
  // lavel 2
  late String dPhone = "",dTime = "";
  bool _dComeing = false;

  @override
  initState() {
    super.initState();
    getLocationUpdates();
    _controllerAnimation = AnimationController(vsync: this);
    Provider.of<ConnectivityProviders>(context,listen: false)
        .startMonitoring();
    firebasedb =  Provider.of<FireBaseDBProvider>(context,listen: false);
    firebasedb.setMethods(
        onApproved: _onApproved,onInTrip: _onInTrip,// onStarted: _onInTrip
        onTripDone: _onTripDone
    );

  }

  @override
  Widget build(BuildContext context) {
    double mapWidth = MediaQuery.of(context).size.width;
    double mapHeight = MediaQuery.of(context).size.height;
       // return pageUI(mapHeight,mapWidth);
    return Consumer<ConnectivityProviders>(
      builder: (context,model,child) {
        return pageUI(mapHeight,mapWidth,model);
      },);
  }

  Widget pageUI(mapHeight,ConnectivityProviders model) {
    return Scaffold(
      appBar: AppBar(
        title: Text(tr('title')),),backgroundColor: Colors.black54,body: Stack(
        children: [
          GoogleMap(
            polylines: polylineSet,mapType: _currentMapType,padding: EdgeInsets.only(bottom: bottomPosition),myLocationButtonEnabled: true,initialCameraPosition: _cameraPosition,myLocationEnabled: true,onCameraMoveStarted: () {
              setState(() {
                _controllerAnimation.forward(from: 0.0);
              });
            },onCameraIdle: () {
              setState(() {
                _controllerAnimation.forward(from: 0.65);
              });
            },tiltGesturesEnabled: true,zoomGesturesEnabled: true,zoomControlsEnabled: false,markers: Set<Marker.Marker>.of(_markersAll.values),onCameraMove: (CameraPosition position) {
              setState(() {
                _cameraMovePosition = position.target;
              });
            },onMapCreated: (GoogleMapController controller) async {
              _controller.complete(controller);
              _googleMapController = controller;

              // _loadPosition();

              _cameraMovePosition =
                  LatLng(_myPosition.latitude,_myPosition.longitude);

              setState(() {
                _cameraMovePosition =
                    LatLng(_myPosition.latitude,_myPosition.longitude);
                bottomPosition = 70;
              });
            },//Marker
          Visibility(
            visible: true,child: Positioned(
                top: (mapHeight - 128 - 240) / 2,right: (mapWidth - 128) / 2,child: IgnorePointer(
                  ignoring: true,child: Lottie.asset(
                      "assets/json_assets/expanding_marker.json",width: 128,height: 160,repeat: false,controller: _controllerAnimation,onLoaded: (composition) {
                    _controllerAnimation.duration = composition.duration;
                    _controllerAnimation.forward(from: 0.50);
                    _controllerAnimation.stop(canceled: true);
                  }),)),//Button GPS AND MAP
          Visibility(
            visible: true,child: Positioned(
              bottom: 110,right: 30,child: Column(
                children: <Widget>[
                  button(_onMapTypeButtonPressed,Icons.map),SizedBox(
                    height: 16.0,button(_loadPosition,Icons.my_location),],//Button Start Trip
          Visibility(
            visible: true,child: Positioned(
              bottom: 40,left: 30,child: Column(
                children: <Widget>[
                  ElevatedButton(
                    style: ElevatedButton.styleFrom(
                      primary: Colors.purple,shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(22.0),onPressed: _goConfTrip,child: Container(
                      width: 150,height: 55,alignment: Alignment.center,child: const Text(
                        'go',style:
                            const TextStyle(fontSize: 24,color: Colors.black),)
                ],/*
          lavel 1
          find driver
           */
          Visibility(
            visible: _findPage,child: Opacity(
              opacity: .5,child: Container(
                height: mapHeight,width: mapWidth,decoration: BoxDecoration(
                    color: Color(0xFFFAB74E),borderRadius: new BorderRadius.circular(10.0),boxShadow: [
                      BoxShadow(
                          color: Colors.grey,blurRadius: 8.0,spreadRadius: 0.8)
                    ]),child: Positioned(
                    top: 1,bottom: 1,right: 1,left: 1,child: Lottie.asset(
                      "assets/json_assets/finding.json",repeat: true,/*
          lavel 2
          driver approv
           */
          Visibility(
              visible: _dComeing,decoration: BoxDecoration(
                  color: Color(0x5F000000),child: Padding(
                  padding: const EdgeInsets.all(20.0),child: Container(
                      margin: EdgeInsets.symmetric(vertical: 130.0),decoration: BoxDecoration(
                          color: Color(0xFFFAB74E),borderRadius: new BorderRadius.circular(20.0),boxShadow: [
                            BoxShadow(
                                color: Colors.grey,spreadRadius: 0.8)
                          ]),child: Padding(
                        padding: const EdgeInsets.all(8.0),child: Column(
                          children: [
                            Lottie.asset("assets/json_assets/car_coming.json",height: 20,width: 60),Text('The car is on the way to you'),SizedBox(
                              height: 5,Text('Expected arrival time : ${dTime}'),Row(
                              crossAxisAlignment: CrossAxisAlignment.center,mainAxisAlignment: MainAxisAlignment.center,children: [
                                Text('Vehicle driver number : '),ElevatedButton(
                                  onPressed: () async {
                                    await FlutterPhoneDirectCaller.callNumber(
                                        dPhone);
                                  },child: Text(dPhone),//No internet
          Visibility(
            visible: (model.isOnline != null) ? !model.isOnline : false,child: NoInternet(),)
        ],);
  }
  void getLocationUpdates(){
    Geolocator.getPositionStream(
        desiredAccuracy: LocationAccuracy.bestForNavigation,distanceFilter: 0).listen((Position position){
      print('latitude');
      print(position.latitude);
      _myPosition = LatLng(position.latitude,position.longitude);
      CameraPosition cameraPosition =
      new CameraPosition(target: _myPosition,zoom: 16);
      _googleMapController
          .animateCamera(CameraUpdate.newCameraPosition(cameraPosition));
    });
  }
  _loadPosition() async {
    print('Are u here');
    Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.bestForNavigation)
        .then((Position _getPosition) {
      setState(() {
        _myPosition = LatLng(_getPosition.latitude,zoom: 16);
        _googleMapController
            .animateCamera(CameraUpdate.newCameraPosition(cameraPosition));
      });
    }).catchError((e) {
      print(e);
    });
    print('Any thing');
  }

  _onMapTypeButtonPressed() {
    setState(() {
      _currentMapType = _currentMapType == MapType.normal
          ? MapType.satellite
          : MapType.normal;
    });
  }

  _goConfTrip() {
    return showDialog<void>(
      context: context,barrierDismissible: false,// user must tap button!
      builder: (BuildContext context) {
        return AlertDialog(
          title: const Text('AlertDialog Title'),content: SingleChildScrollView(
            child: ListBody(
              children: const <Widget>[
                Text('This is a demo alert dialog.'),Text('Would you like to approve of this message?'),actions: <Widget>[
            TextButton(
              child: const Text('Approve'),onPressed: _finddrivers,TextButton(
              child: const Text('Cancel'),onPressed: () {
                Navigator.of(context).pop();
              },);
      },);
  }

  _finddrivers() {
    Navigator.of(context).pop();
    setState(() {
      _findPage = true;
    });
    firebasedb.startRequest(_cameraMovePosition.latitude,_cameraMovePosition.longitude);
  }

  _onApproved(Trip _trip) {
    setState(() {
      _dComeing = true;
      dPhone = _trip.driverID;
      dTime = _trip.time;
    });

  }

  void _onInTrip(Trip p1) {}

  void _onTripDone(Trip p1) {

  }
}

记录问题 https://drive.google.com/file/d/1LKiC4EbRYAsk-7BEF9FInXW0V_SWCtlS/view?usp=sharing 另外,为什么在视频中多次显示消息?喜欢循环。

我也试过使用 location 也不起作用

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)&gt; insert overwrite table dwd_trade_cart_add_inc &gt; select data.id, &gt; data.user_id, &gt; data.course_id, &gt; date_format(
错误1 hive (edu)&gt; insert into huanhuan values(1,&#39;haoge&#39;); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive&gt; show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 &lt;configuration&gt; &lt;property&gt; &lt;name&gt;yarn.nodemanager.res