Advertisement
Guest User

Untitled

a guest
May 20th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. extension MKMapView {
  2. func fitMapViewToAnnotaion(withEdgePadding edgePadding:UIEdgeInsets = UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20), andLocation givenLocation:CLLocationCoordinate2D?) -> Void {
  3. var zoomRect:MKMapRect = MKMapRect.null
  4.  
  5. for annotation in annotations {
  6. let aPoint:MKMapPoint = MKMapPoint(annotation.coordinate)
  7. let rect:MKMapRect = MKMapRect(x: aPoint.x, y: aPoint.y, width: 0.1, height: 0.1)
  8.  
  9. if zoomRect.isNull {
  10. zoomRect = rect
  11. } else {
  12. zoomRect = zoomRect.union(rect)
  13. }
  14. }
  15.  
  16. if let location = givenLocation {
  17. let aPoint:MKMapPoint = MKMapPoint(location)
  18. let rect:MKMapRect = MKMapRect(x: aPoint.x, y: aPoint.y, width: 0.1, height: 0.1)
  19.  
  20. if zoomRect.isNull {
  21. zoomRect = rect
  22. } else {
  23. zoomRect = zoomRect.union(rect)
  24. }
  25. }
  26.  
  27. setVisibleMapRect(zoomRect, edgePadding: edgePadding, animated: true)
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement