【发布时间】:2020-08-17 09:38:12
【问题描述】:
我想在我的应用程序中持续跟踪用户位置。出于这个原因,我想在我的主页中连续执行 getLocaiton bloc 事件。我该怎么做?
这是我的 getLocation 事件;
GetLocationState get initialState => GetLocationState(saveUserCurrentLocation: initialPosition );
Stream<GetLocationState> mapEventToState(LocationEvent event) async*{
if (event is GetLocation){
userLocation.getLocation().then((l){
currentLatLng = LatLng(l.latitude, l.longitude);
});
yield GetLocationState(saveUserCurrentLocation: currentLatLng);
}
}
这是我的主页
initialCameraPosition:
CameraPosition(target: initialPosition, zoom: 10),
mapType: MapType.terrain,
onMapCreated: _onMapCreated,
myLocationEnabled: true,
),
floatingActionButton: FloatingActionButton(
onPressed: () {
_locationBloc.add(GetLocation());
},
),
),
);
});
}
如何在不使用 onPress 事件的情况下在后台连续运行代码?
【问题讨论】:
标签: google-maps flutter dart mobile