【问题标题】:How to limit google map view using place id?如何使用地点 ID 限制谷歌地图视图?
【发布时间】:2020-07-18 18:43:00
【问题描述】:

是否可以使用地点 ID 限制谷歌地图视图?(城市)

缩放和查看,仅获取 lat 和 lng 限制视图。

GoogleMap(
      mapType: MapType.normal,
      initialCameraPosition: cameraPosition,
      onMapCreated: (GoogleMapController controller) {
      },
    );

【问题讨论】:

  • @AnuragSrivastava 是的。谢谢。是否可以在 Flutter 上使用
  • 如果你能正确整合地图应该是可能的
  • 您可以使用地点 ID 进行地点详细信息请求,至少请求 fields 中的 geometry 字段,该字段应返回 viewport,根据文档 包含首选在地图上显示此地点时的视口。然后,您应该能够在 Flutter 中将视口边界对象用作 cameraTargetBounds
  • @MrUpsidown 非常感谢您的支持。抱歉回复晚了。这对我很有帮助。我会尽力让你知道。再次抱歉

标签: google-maps flutter dart


【解决方案1】:

您可以使用控制器设置边界并为相机设置动画,例如:

LatLngBounds getLatLngBounds() {
    //this.points is a List<LatLng> representing vertex of a polygon, it could be a city.
    var maxLat = this.points.map((latlng) => latlng.latitude).reduce(max);
    var maxLng = this.points.map((latlng) => latlng.longitude).reduce(max);
    var minLat = this.points.map((latlng) => latlng.latitude).reduce(min);
    var minLng = this.points.map((latlng) => latlng.longitude).reduce(min);

    return LatLngBounds(
        northeast: LatLng(maxLat, maxLng), southwest: LatLng(minLat, minLng));
  }

要为相机设置动画:

...
onMapCreated: (GoogleMapController controller) async {
              try {
                controller.animateCamera(
                    CameraUpdate.newLatLngBounds(getLatLngBounds(), 50)
              } on Exception catch (e) {
                print(e);
              }
            },
...

此解决方案要求您从该特定地点 ID 获取多边形。

【讨论】:

    猜你喜欢
    • 2012-09-10
    • 1970-01-01
    • 2015-10-25
    • 2016-11-10
    • 2017-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多