google-maps - Flutter - AnimateCamera 无法与 newLatLngBounds 一起使用
问题描述
我正在使用谷歌地图,在添加了很多标记后,我想将相机移动到 newLatLngBounds 以显示用户可见的所有标记。但我正面临这个错误。
使用 newLatLngBounds(LatLngBounds, int) 时出错:地图大小不能为 0。很可能,地图视图的布局尚未发生。要么等到布局发生,要么使用 newLatLngBounds(LatLngBounds, int, int, int) 允许您指定地图的尺寸。, null)
Future<void> getCenterMap() async {
double minlatitude = loadInformationMap[0]['latlng'].latitude,
maxlatitude = loadInformationMap[0]['latlng'].latitude,
minlongitude = loadInformationMap[0]['latlng'].longitude,
maxlongitude = loadInformationMap[0]['latlng'].longitude;
for (int i = 0; i < loadInformationMap.length; i++) {
if (minlatitude >= loadInformationMap[i]['latlng'].latitude) {
minlatitude = loadInformationMap[i]['latlng'].latitude;
}
if (minlongitude >= loadInformationMap[i]['latlng'].longitude) {
minlongitude = loadInformationMap[i]['latlng'].longitude;
}
if (maxlatitude <= loadInformationMap[i]['latlng'].latitude) {
maxlatitude = loadInformationMap[i]['latlng'].latitude;
}
if (maxlongitude <= loadInformationMap[i]['latlng'].longitude) {
maxlongitude = loadInformationMap[i]['latlng'].longitude;
}
}
googleMapController.animateCamera(CameraUpdate.newLatLngBounds(
LatLngBounds(
southwest: LatLng(minlatitude, minlongitude),
northeast: LatLng(maxlatitude, maxlongitude)),
100));
}
解决方案
推荐阅读
- ionic-framework - 离子原生联系人cordova插件已弃用?任何替代解决方案?
- javascript - 如何仅向 datalist 元素添加唯一选项?
- r - 按 R 中的变量分组,然后运行 dplyr case_when
- android - 如何从属于 viewPager 的另一个 Fragment 中启动一个 Fragment?
- python - Python 运算符和格式
- sql - 如何在哪里格式化日期?
- kframework - 上下文在 K 中究竟做了什么?
- python - Tornado 在 chalice python 中抛出流关闭错误
- aws-lambda - AWS SAM 在 serverless.template 中设置基于 lambda 资源的策略
- python - 给定 N 的 toeplitz 矩阵