How to fit bounds for coordinate array with google maps sdk for iOS?

后端 未结 5 1411
我在风中等你
我在风中等你 2021-01-31 17:23

How to fit bounds for coordinate array with google maps sdk for iOS? I need to zoom map for 4 visible markers.

5条回答
  •  清歌不尽
    2021-01-31 17:45

    We can simplify this quite a bit, with code such as the following:

    extension Array where Element: GMSMarker {
      func encompassingCoordinateBounds() -> GMSCoordinateBounds {
        reduce(GMSCoordinateBounds(), { $0.includingCoordinate($1.position) })
      }
    }
    

    The call site would like:

    let markers = [GMSMarker]()
    let encompassingCoordinateBounds = markers.encompassingCoordinateBounds()
    

提交回复
热议问题