我试图在谷歌地图可见区域中拟合两个地理定位点,但不拟合。我使用下面的代码来实现这个
let bounds = GMSCoordinateBounds(coordinate: source, coordinate: destination)
self.mapView.animate(with: GMSCameraUpdate.fit(bounds, withPadding: 10))
https://i.stack.imgur.com/8AZa1.png
您可以使用includeCoordinate。它将适用于边界内的所有坐标。
var bounds = GMSCoordinateBounds()
bounds = bounds.includingCoordinate(source)
bounds = bounds.includingCoordinate(destination)
self.mapView.animate(with: GMSCameraUpdate.fit(bounds, withPadding: 10.0))
已更新
let bounds = GMSCoordinateBounds(coordinate: source, coordinate: destination)
self.mapView.animate(with: GMSCameraUpdate.fit(bounds, withPadding: 100))
mapView.padding = UIEdgeInsets(top: 0, left: 0, bottom: self.bottomView.height, right: 0)