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

后端 未结 5 1409
我在风中等你
我在风中等你 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:54

    Swift 5 version of Lirik's answer:

        func focusMapToShowAllMarkers() {
    
            if arrMarkers.count > 0 {
                let firstLocation = (arrMarkers.first!).position
                var bounds = GMSCoordinateBounds(coordinate: firstLocation, coordinate: firstLocation)
    
                for marker in arrMarkers {
                  bounds = bounds.includingCoordinate(marker.position)
                }
    
               let update = GMSCameraUpdate.fit(bounds, withPadding: CGFloat(15))
               self.mapView.animate(with: update)
            }
        }
    

提交回复
热议问题