集成用户位置不起作用



我试图构建一个应用程序,它显示当前用户位置。为了实现这个目标,我使用了谷歌地图和位置插件。我尝试了在网上找到的一个样本,但我出现了一个错误,不知道为什么。。。我想我做的和视频中的那个人做的一样…

这是我试过的颂歌:

void _onMapCreated(GoogleMapController controller) {
_controller = controller;
_location.onLocationChanged().listen((l) {
_controller.animateCamera(CameraUpdate.newCameraPosition(
CameraPosition(target: LatLng(l.latitude, l.lomgitude), zoom: 10)));
});
}
child: GoogleMap(
markers: markers,
initialCameraPosition: position,
mapType: MapType.hybrid,
onMapCreated: _onMapCreated,
myLocationButtonEnabled: true,
),

这是我得到的错误:

Compiler message:
lib/main.dart:42:32: Error: 'onLocationChanged' isn't a function or method and can't be invoked.
_location.onLocationChanged().listen((l) {
^^^^^^^^^^^^^^^^...

有人发现我的错误吗?

您可以删除onLocationChanged()()
请从
更改

_location.onLocationChanged().listen((l) {
_controller.animateCamera(CameraUpdate.newCameraPosition(
CameraPosition(target: LatLng(l.latitude, l.lomgitude), zoom: 10)));
});

_location.onLocationChanged.listen((l) {
_controller.animateCamera(CameraUpdate.newCameraPosition(
CameraPosition(target: LatLng(l.latitude, l.lomgitude), zoom: 10)));
});

最新更新