Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extension MKMapView {
- func fitMapViewToAnnotaion(withEdgePadding edgePadding:UIEdgeInsets = UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20), andLocation givenLocation:CLLocationCoordinate2D?) -> Void {
- var zoomRect:MKMapRect = MKMapRect.null
- for annotation in annotations {
- let aPoint:MKMapPoint = MKMapPoint(annotation.coordinate)
- let rect:MKMapRect = MKMapRect(x: aPoint.x, y: aPoint.y, width: 0.1, height: 0.1)
- if zoomRect.isNull {
- zoomRect = rect
- } else {
- zoomRect = zoomRect.union(rect)
- }
- }
- if let location = givenLocation {
- let aPoint:MKMapPoint = MKMapPoint(location)
- let rect:MKMapRect = MKMapRect(x: aPoint.x, y: aPoint.y, width: 0.1, height: 0.1)
- if zoomRect.isNull {
- zoomRect = rect
- } else {
- zoomRect = zoomRect.union(rect)
- }
- }
- setVisibleMapRect(zoomRect, edgePadding: edgePadding, animated: true)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement