簡體   English   中英

Geolocator 包不起作用,Flutter

[英]Geolocator package is not working, Flutter

我正在嘗試使用 Geolocator 包在 Flutter 中獲取當前的地理位置,但它不起作用。 這是我的函數代碼:

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

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

  print(position);
}

它正在打印 NULL。

注意:我已經在 AndroidManifest 中設置了適當的權限以及地理定位器 API 密鑰。

地理定位器包版本:5.3.0

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!

沒有發現 Geolocator 包的問題,​​所以我使用了 Locator 包,效果很好。

這是我的功能:

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