gpt4 book ai didi

android - 无法通过地理定位器在 Flutter 中检索位置

转载 作者:行者123 更新时间:2023-12-02 02:09:50 25 4
gpt4 key购买 nike

我正在开发一个 flutter 应用程序,我制作了一个类,该类使用 geolocator 包检索当前位置并通过 iOS 模拟器进行调试,但它不检索任何数据。定位服务的图标只是空心图标,没有接收到数据。

位置类:

import 'package:geolocator/geolocator.dart';

class LocationServices {
double latitude;
double longitude;

Future<void> getCurrentLocation() async {
try {
Position position = await Geolocator()
.getCurrentPosition(desiredAccuracy: LocationAccuracy.best);

latitude = position.latitude;
longitude = position.longitude;
print(latitude);
print(longitude);
} catch (e) {
print(e);
}
}
}

调用该函数的初始状态:

@override
void initState() {
// TODO: implement initState
super.initState();
_animationController = AnimationController(
vsync: this,
duration: Duration(seconds: 4),
);
_opacity = Tween<double>(begin: 0.0, end: 1).animate(_animationController);
_animationController.forward();
NetworkManager.checkConnectivity();
// apiServices.getPrayerTimes();
locationServices.getCurrentLocation();
}

信息.plist文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>muslim_2b</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>NSLocationWhenInUseUsageDescription</key>
<string>This app needs access to location when open.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>This app needs access to location when in the background.</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>This app needs access to location when open and in the background.</string>
</dict>
</plist>

The Location icon is hollow

最佳答案

我也遇到了这个问题,我已经设置了模拟器的位置。我通过更改 Mac 上的位置首选项解决了这个问题。系统偏好设置 -> 安全和隐私 -> 启用定位服务(我为 Chrome 和 Visual Studio Code 都启用了)。

关于android - 无法通过地理定位器在 Flutter 中检索位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67870103/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com