flutter - 如何在地图中的两个标记之间进行缩放
问题描述
我尝试用颤动放大地图中的两个标记,但我没有在颤动 fitBounds 中找到方法。
getRouteCoordinates(_initialPosition, destination);
*LatLngBounds bound = LatLngBounds(northeast: initialPosition,southwest: destination);
//mapController.getVisibleRegion();
CameraUpdate u2 = CameraUpdate.newLatLngBounds(bound, 10);
this.mapController.animateCamera(u2).then((void v){
check(u2,this.mapController);
});
void check(CameraUpdate u, GoogleMapController c) async {
c.animateCamera(u);
mapController.animateCamera(u);
LatLngBounds l1=await c.getVisibleRegion();
LatLngBounds l2=await c.getVisibleRegion();
print(l1.toString());
print(l2.toString());
if(l1.southwest.latitude==-90 ||l2.southwest.latitude==-90)
check(u, c);
}
解决方案
首先,从您的 GeoPoint 中创建一个列表,并创建一个函数来选择边界点。
LatLngBounds boundsFromLatLngList(List<LatLng> list) {
assert(list.isNotEmpty);
double x0, x1, y0, y1;
for (LatLng latLng in list) {
if (x0 == null) {
x0 = x1 = latLng.latitude;
y0 = y1 = latLng.longitude;
} else {
if (latLng.latitude > x1) x1 = latLng.latitude;
if (latLng.latitude < x0) x0 = latLng.latitude;
if (latLng.longitude > y1) y1 = latLng.longitude;
if (latLng.longitude < y0) y0 = latLng.longitude;
}
}
return LatLngBounds(northeast: LatLng(x1, y1), southwest: LatLng(x0, y0));
}
之后调用此函数并进行缩放
LatLngBounds bound = boundsFromLatLngList(listmap);
await Future.delayed(Duration(milliseconds:500)).then((v) async {
CameraUpdate u2 = CameraUpdate.newLatLngBounds(bound, 50);
this.mapController.animateCamera(u2).then((void v) {
check(u2, this.mapController);
});
});
这个代码片段对我有用
推荐阅读
- python - Python - 如何用另一个字符串替换文本文件中的某一行?
- python-3.x - 通过替换列表中的子字符串来创建字符串的笛卡尔积
- html - 使用 ontouchmove 移动片段时,画布不会重绘
- python-2.7 - 使用 Python 进行语言翻译
- tabs - 在 Net Core 3.1 MVC 中的多个选项卡上使用表单
- python - 与python中没有顺序的字符串列表进行比较
- c++ - 使用可变参数类模板的模板参数调用可变参数函数模板?
- python - 如何通过 python 将自定义日期时间插入 sql?
- video - 如何基于 Azure 文本转语音将 Visimes ID 与我的 svg 图像框架文件夹连接
- java - 为什么我得到 Java.lang.IllegalArgumentException:使用反射创建带有私有构造函数的新实例时参数数量错误