Change Camera Zoom based on Radius Google Maps iOS SDK

前端 未结 6 820
既然无缘
既然无缘 2021-02-01 09:53

I am working on an app that displays certain markers based on a radius around your current location. The radius is between 100 - 5000 meters. I change the radius with an U

6条回答
  •  北海茫月
    2021-02-01 10:16

    I just created extension for GMSCameraUpdate.

    input parameters:

    coordinate - your center coordinate

    radius - radius of visible bounds

    extension GMSCameraUpdate {
    
        static func fit(coordinate: CLLocationCoordinate2D, radius: Double) -> GMSCameraUpdate {
            var leftCoordinate = coordinate
            var rigthCoordinate = coordinate
    
            let region = MKCoordinateRegionMakeWithDistance(coordinate, radius, radius)
            let span = region.span
    
            leftCoordinate.latitude = coordinate.latitude - span.latitudeDelta
            leftCoordinate.longitude = coordinate.longitude - span.longitudeDelta
            rigthCoordinate.latitude = coordinate.latitude + span.latitudeDelta
            rigthCoordinate.longitude = coordinate.longitude + span.longitudeDelta
    
            let bounds = GMSCoordinateBounds(coordinate: leftCoordinate, coordinate: rigthCoordinate)
            let update = GMSCameraUpdate.fit(bounds, withPadding: -15.0)
    
            return update
        }
    
    }
    

提交回复
热议问题