简体   繁体   English

Geolocator 包不起作用,Flutter

[英]Geolocator package is not working, Flutter

I am trying to get the current geolocation in Flutter using the Geolocator package but it's not working.我正在尝试使用 Geolocator 包在 Flutter 中获取当前的地理位置,但它不起作用。 Here is my function code:这是我的函数代码:

local() async {
  final Geolocator geolocator = Geolocator()..forceAndroidLocationManager = true;

  var position = await geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.low);

  print(position);
}

It's printing NULL.它正在打印 NULL。

Note : I have set the proper permissions in AndroidManifest along with the geolocator API key.注意:我已经在 AndroidManifest 中设置了适当的权限以及地理定位器 API 密钥。

Geolocator package version : 5.3.0地理定位器包版本:5.3.0

Flutter Doctor: (I can't use the last version of flutter currently) Flutter Doctor:(我目前无法使用最后一个版本的flutter)

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.17.5, on Linux, locale en_US.UTF-8)
 
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[✓] Android Studio (version 3.6)
[✓] VS Code (version 1.48.2)
[✓] Connected device (1 available)

• No issues found!

Didn't find the problem with the Geolocator package, so i used the Locator package and it worked fine.没有发现 Geolocator 包的问题,​​所以我使用了 Locator 包,效果很好。

Here's my function :这是我的功能:

import 'package:location/location.dart';

LocationData locationData;

local() async {
    Location location = new Location();

    locationData = await location.getLocation();
    print(locationData);
  }

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

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