gpt4 book ai didi

flutter - 使用地理定位器的当前位置

转载 作者:IT王子 更新时间:2023-10-29 06:57:30 25 4
gpt4 key购买 nike

我正在尝试使用 flutter 的 geolocator sdk 获取当前位置。但我收到此错误。

这是堆栈跟踪

/flutter/.pub-cache/hosted/pub.dartlang.org/geolocator-2.1.1/android/src/main/java/com/baseflow/flutter/plugin/geolocator/tasks/LastKnownLocationUsingLocationServicesTask.java:4: error: package android.support.annotation does not exist
import android.support.annotation.NonNull;
^
/flutter/.pub-cache/hosted/pub.dartlang.org/geolocator-2.1.1/android/src/main/java/com/baseflow/flutter/plugin/geolocator/tasks/LocationUpdatesUsingLocationServicesTask.java:5: error: package android.support.annotation does not exist
import android.support.annotation.NonNull;
^
symbol: class NonNull
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
4 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':geolocator:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

我想像这样获取当前位置

    class _MapActivityState extends State<MapActivity> {

Position currentLocation;

@override
void initState() {
// TODO: implement initState
super.initState();
getUserLocation();
}
@override
Widget build(BuildContext context) {
return Container(
child: MapboxMap(
initialCameraPosition: CameraPosition(target: _center, zoom: 15),
onMapCreated: _onMapCreated,
myLocationEnabled: true,
),
);
}
Future<Position> locateUser() async {
return Geolocator()
.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
}

getUserLocation() async {
currentLocation = await locateUser();
print(currentLocation);
}
}

感谢任何帮助

最佳答案

打开 LastKnownLocationUsingLocationServicesTask 文件,删除导致此错误的导入语句,再次使用 option + enter 导入它,我在使用 geolocator 时看到了这个问题

同样,打开 LocationUpdatesUsingLocationServicesTask 文件并删除导入(有错误)并重新导入。

关于flutter - 使用地理定位器的当前位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55629722/

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