google-maps - 如何在 Flutter 中连续跟踪用户位置?
问题描述
我想跟踪用户位置。出于这个原因,我正在使用颤振的位置包。同样,我正在使用 Streams 进行实时跟踪。但是如何在谷歌地图上实时显示用户位置。我在 Google 地图上显示实时位置时遇到了一些问题。
** 这是我的位置服务课程 **
class LocationService {
UserLocation _currentLocationofUser;
Location location = Location();
//Sürekli güncelle
StreamController<UserLocation> _locationController =
StreamController<UserLocation>.broadcast();
LocationService() {
location.requestPermission().then((granted) {
if (granted != null) {
location.onLocationChanged.listen((locationData) {
if (locationData != null) {
_locationController.add(UserLocation(
latitude: locationData.latitude,
longitude: locationData.longitude));
}
});
}
});
}
Stream<UserLocation> get locationStream => _locationController.stream;
** 这是我的主要课程,用于显示用户的实时位置 **
@override
_HomeViewState createState() => _HomeViewState();
}
class _HomeViewState extends State<HomeView> {
GoogleMapController _mapController;
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
var userLocation = Provider.of<UserLocation>(context);
return GoogleMap(
mapType: MapType.normal,
initialCameraPosition: CameraPosition(
zoom: 12,
target: LatLng(userLocation.latitude, userLocation.longitude)),
onMapCreated: (GoogleMapController controller) {
_mapController = controller;
},
);
}
}
解决方案
推荐阅读
- amazon-web-services - elasticbeanstalk 描述应用程序版本返回空
- apollo - Apollo Client GraphQL 在 Next.js getStaticProps 上创建静态页面
- javascript - 如何将 js 表数据转换为 .csv 表?
- python - Python 3.6、3.7、3.8 上的 Python ImportError,但 3.9 上没有
- python - KeyError:“[Float64Index([xxxxxx,yyyy,zzzz....]) 都不在 [index] 中
- flutter - 如何禁用颤振开关
- firebase - 永远不会调用 Firebase 消息传递 onResume、onLaunch 或 onBackgroundMessage
- java - Audiosystem 过早停止写入 AudioInputStream
- neo4j - 合并重复路径
- python - 如何确定传递给函数的参数数量?