在Google地图可见区域拟合两个地理位置点

时间:2018-07-13 19:41:30

标签: ios swift google-maps geolocation

我正在尝试在Google地图可见区域中适合两个地理位置点,但不适合。我使用下面的代码来实现这一点

let bounds = GMSCoordinateBounds(coordinate: source, coordinate: destination)
self.mapView.animate(with: GMSCameraUpdate.fit(bounds, withPadding: 10))

https://i.stack.imgur.com/8AZa1.png

1 个答案:

答案 0 :(得分:1)

您可以为此使用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)