gpt4 book ai didi

google-maps - 相机动画和用户相机移动之间的区别

转载 作者:行者123 更新时间:2023-12-04 16:45:57 26 4
gpt4 key购买 nike

我目前正在使用 GoogleMap在 flutter 中。我也用 clustering_google_maps显示标记簇的包。这个插件的默认行为是每次相机移动都会触发所有标记和集群的更新。此行为考虑了用户放大/缩小和平移。

我在 location 中添加了一个相机根据用户位置移动的功能。包裹。

  initPlatformState() async {
// Wait for the Completer to complete and return the GoogleMap Controler
mapController = await _controller.future;
// Set controller for the ClusteringHelper
clusteringHelper.mapController = mapController;

// Get database and update markers
clusteringHelper.database = await DBHelper().database;
clusteringHelper.updateMap();

// Set parameters for location Service
await _locationService.changeSettings(
accuracy: LocationAccuracy.HIGH, interval: 1000);

try {
bool serviceStatus = await _locationService.serviceEnabled();
print("Service status: $serviceStatus");
if (serviceStatus) {
_permission = await _locationService.requestPermission();
print("Permission: $_permission");

// If permission granted, get current location and subscribe to updates
if (_permission) {
LocationData location = await _locationService.getLocation();

final myLocationMarkerId = MarkerId("myLocationMarker");
myLocationMarker = Marker(
markerId: myLocationMarkerId,
position: LatLng(location.latitude, location.longitude),
icon: BitmapDescriptor.defaultMarker,
infoWindow: InfoWindow(
title: "My Location",
snippet: "Latitude: " +
location.latitude.toString() +
" Longitude: " +
location.longitude.toString()),
);

_locationSubscription = _locationService
.onLocationChanged()
.listen((LocationData result) async {
if (cameraUpdateToMyLocation) {

_currentCameraPosition = CameraPosition(
target: LatLng(result.latitude, result.longitude), zoom: 16);

// Safety check if mapController not null
if (mapController != null) {
mapController.animateCamera(
CameraUpdate.newCameraPosition(_currentCameraPosition));
}
}

if (mounted) {
setState(() {
_currentLocation = result;
myLocationMarker = myLocationMarker.copyWith(
positionParam: LatLng(
_currentLocation.latitude, _currentLocation.longitude),
infoWindowParam: InfoWindow(
title: "My Location",
snippet: "Latitude: " +
location.latitude.toString() +
" Longitude: " +
location.longitude.toString())
);

});
}
});
}
} else {
bool serviceStatusResult = await _locationService.requestService();
print("Service status activated after request: $serviceStatusResult");
if (serviceStatusResult) {
initPlatformState();
}
}
} on PlatformException catch (e) {
print(e);
if (e.code == 'PERMISSION_DENIED') {
error = e.message;
} else if (e.code == 'SERVICE_STATUS_ERROR') {
error = e.message;
}
}
}

我希望当用户在屏幕上移动 map 时停止位置更新。

不幸的是,回调 onCameraMove 在用户移动 map 和启动相机动画时被触发。

是否可以仅在用户移动 map 时触发 inCameraMove 回调?

谢谢!

编辑 当我用手指拖动 map 时,似乎在循环中调用了 onCameraMove...

最佳答案

据我所知,不可能区分 onCameraMove 回调。你想在这里完成什么?您可以更改插件以显示集群 onCameraIdle 回调吗?这会解决您的问题吗?

关于google-maps - 相机动画和用户相机移动之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58891241/

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