google-maps - 中心折线谷歌地图插件 flutter 适合屏幕谷歌地图

标签 google-maps flutter dart

想要找到 2 个点的中心并拟合 map 。
我想在 map 上查看时适合所有屏幕。
我准备好路线,但它只适合 1 点。请帮我。
此类用于 flutter 的 map View 。
我尝试寻找更多的插件和解决方案,但仍然没有找到。

 GoogleMap(
              mapType: MapType.normal,
              markers: _markers,
//              cameraTargetBounds: CameraTargetBounds(new LatLngBounds(
//                  northeast: LatLng(latFrom, logFrom),
//                  southwest: LatLng(latTo, logTo),
//              )),
//              minMaxZoomPreference: MinMaxZoomPreference(1, 15),
              mapToolbarEnabled: true,
              scrollGesturesEnabled: true,
              zoomGesturesEnabled: true,
              trafficEnabled: true,
              compassEnabled: true,
              indoorViewEnabled: true,
              rotateGesturesEnabled: true,
              tiltGesturesEnabled: true,
              myLocationButtonEnabled: true,
              myLocationEnabled: true,
              polylines: _polyline,
//              padding: EdgeInsets.all(20),
              initialCameraPosition:
                  CameraPosition(
                      target: LatLng(latFrom, logFrom),
                      zoom: 10,
                  ),
              onMapCreated: (GoogleMapController controller) {
                _controller.complete(controller);
              })

最佳答案

void _setMapFitToTour(Set<Polyline> p) {
    double minLat = p.first.points.first.latitude;
    double minLong = p.first.points.first.longitude;
    double maxLat = p.first.points.first.latitude;
    double maxLong = p.first.points.first.longitude;
    p.forEach((poly) {
      poly.points.forEach((point) {
        if(point.latitude < minLat) minLat = point.latitude;
        if(point.latitude > maxLat) maxLat = point.latitude;
        if(point.longitude < minLong) minLong = point.longitude;
        if(point.longitude > maxLong) maxLong = point.longitude;
      });
    });
    mapController.moveCamera(CameraUpdate.newLatLngBounds(LatLngBounds(
      southwest: LatLng(minLat, minLong),
      northeast: LatLng(maxLat,maxLong)
    ), 20));
  }

关于google-maps - 中心折线谷歌地图插件 flutter 适合屏幕谷歌地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57986855/

相关文章:

javascript - 除非刷新,否则谷歌地图无法正确显示

flutter - 有没有一种简单的方法来交叉验证 Flutter Form TextFormFields?

Flutter - 在 setState 内部或外部更改变量?

Flutter TextFormField 文本在溢出时隐藏

android - 在firebase,flutter中应该如何处理好友请求和邀请?

google-maps - React-google-maps 重新渲染问题

iphone - iOS : How to enable Audio directions on Google Maps

caching - 如何缓存 Google map 图 block 以供离线使用?

flutter - 无法以健全的空安全运行,因为以下依赖项不支持空安全

firebase - 如何在flutter中的Firebase身份验证中验证电子邮件?