iOS, How to use GMSCoordinateBounds to show all the markers of the map?

后端 未结 10 1914
无人共我
无人共我 2020-12-23 09:28

I want to show all the markers that are on my map, after doing some searches I found that it should be done with GMSCoordinateBounds (Google Maps SDK) I\'ve

10条回答
  •  南笙
    南笙 (楼主)
    2020-12-23 10:17

    Clean swift 3 version:

    let bounds = markers.reduce(GMSCoordinateBounds()) { 
        $0.includingCoordinate($1.position) 
    }
    
    mapView.animate(with: .fit(bounds, withPadding: 30.0))
    

提交回复
热议问题