简体   繁体   English

Flutter 地理定位器 5.0.1 无法正常工作

[英]Flutter Geolocator 5.0.1 not working properly

I'm having a problem with the flutter geolocator: ^5.0.1 dependencies.我在使用 flutter 地理定位器时遇到问题:^5.0.1 依赖项。 Bt it doesn't show the location also not showing any error. Bt 它没有显示位置,也没有显示任何错误。 I have given permission in the manifest file also.我也在清单文件中给予了许可。

I'm using flutter stable version 1.22.6 and for this project compile SDK version is 29.我正在使用 flutter 稳定版本 1.22.6 并且对于这个项目编译 SDK 版本是 29。

Manifest file:清单文件:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />`

Flutter Code for getting location: Flutter 获取位置代码:

                  String specificAddress;
                  try {
                    Position position = await Geolocator()
                        .getCurrentPosition(
                            desiredAccuracy: LocationAccuracy.best);
                    List<Placemark> placeMarks = await Geolocator()
                        .placemarkFromCoordinates(
                            position.latitude, position.longitude);
                    Placemark mPlaceMark = placeMarks[0];

                    // String completeAddressInfo =
                    //     "${mPlaceMark.subThoroughfare} ${mPlaceMark.thoroughfare}, " +
                    //         "${mPlaceMark.subLocality} ${mPlaceMark.locality}, " +
                    //         "${mPlaceMark.subAdministrativeArea} ${mPlaceMark.administrativeArea}, " +
                    //         "${mPlaceMark.postalCode} ${mPlaceMark.country}, ";

                    specificAddress =
                        "${mPlaceMark.subLocality}, ${mPlaceMark.locality}, ${mPlaceMark.country}";

                    locationTextEditingController.text = specificAddress;
                    setState(() {
                      _location = specificAddress;
                    });
                  } catch (e) {
                    _showSnackbar(e.toString());
                  }`

Error > when I press the "get my location button" it shows nothing....错误> 当我按下“获取我的位置按钮”时,它什么也没有显示......

在此处输入图像描述

What can I try to resolve this?我可以尝试什么来解决这个问题?

The geolocator package has a newer version, try updating to that.地理定位器 package 有更新版本,请尝试更新。

You can choose to you use either ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION but not both in the same AndroidManifest.xml file.您可以选择在同一个 AndroidManifest.xml 文件中使用ACCESS_FINE_LOCATIONACCESS_COARSE_LOCATION但不能同时使用两者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM