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

后端 未结 10 1893
无人共我
无人共我 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:02

    As for Google Maps version 2.0.0 if you try to create a GMSCoordinateBounds using the default constructor GMSCoordinateBounds() and you check the "valid" flag it will be returning false and it won't make the animateWithCameraUpdate: move.

    Swift 2.3 Solution

        if let myLocation = mapView.myLocation {
            let path = GMSMutablePath()
            path.addCoordinate(myLocation.coordinate)
    
            //add other coordinates 
            //path.addCoordinate(model.coordinate)
    
            let bounds = GMSCoordinateBounds(path: path)
            mapView.animateWithCameraUpdate(GMSCameraUpdate.fitBounds(bounds, withPadding: 40))
        }
    

提交回复
热议问题