flutter - 如何在 map 中的两个标记之间进行缩放

标签 flutter dart maps

我尝试使用flutter放大 map 中的两个标记,但未在flit 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));
}

After That调用此功能并进行缩放
  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);
  });
});

此代码段对我有用

关于flutter - 如何在 map 中的两个标记之间进行缩放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58753109/

相关文章:

dart - 为什么 "Navigator operation requested with a context that does not include a Navigator"

android-studio - 运行我的第一个 flutter 项目时出错

flutter - 在 Dart 中将 int 转换为 Uint8

dart - Flutter 在 ListView 或 PageView 中跳过 child

google-maps - 我们可以在 google_maps_flutter 中为国家/地区填充颜色吗?

r - R中具有 map 和图层的ggplot2 stat_density2d的透明度和Alpha级别

php - 从用户 ip 地址查找位置和区域

class - Flutter中的颜色和颜色类

Flutter 是否可以在不创建新状态的情况下推送已经初始化的页面?

dart - 找不到发布服务的Transformer库 “package:observe/transformer.dart”