如何从边界设置 GMSCameraPosition

问题描述 投票:0回答:1

我有一个坐标列表,我希望在我的 Google 地图上可见。

对于 MapKit,我可以创建一个

MKCoordinateRegion
,其中包含我的所有坐标,然后将我的应用程序设置为该区域。

Google 地图使用

GMSCameraPosition
来获取坐标和缩放级别。我不明白将其设置为地图上的特定区域。

我尝试创建这样的边界并更新相机,但没有任何反应。

let bounds = GMSCoordinateBounds()
for coordinate in coordinates {
    bounds.includingCoordinate(coordinate)
}

let update = GMSCameraUpdate.fit(bounds)
mapView.moveCamera(update)

我将我的 Google 地图视图包装在 SwiftUI 的

UIViewRepresentable
中,理想情况下,我想通过更改相机位置来从我的坐标列表中更新相机。有没有办法用
GMSCameraPosition
制作
GMSCoordinateBounds

swift swiftui google-maps-sdk-ios
1个回答
0
投票

根据文档,GMSColinedBounds 无法更改。 您应该添加如下所示的边界

var bounds = GMSCoordinateBounds()
for coordinate in coordinates {
    bounds = bounds.includingCoordinate(coordinate)
}
© www.soinside.com 2019 - 2024. All rights reserved.