In iOS7, rectForMapRect: and mapRectForRect: are deprecated and are now part of the MKOverlayRenderer class. I would prefer to use the MapView methods mapRectThatFits: edgePadding: Here is a sample code:
MKMapRect visibleRect = self.mapView.visibleMapRect; UIEdgeInsets insets = UIEdgeInsetsMake(50, 50, 50, 50); MKMapRect biggerRect = [self.mapView mapRectThatFits:visibleRect edgePadding:insets];
The latest version of Swift for 2017.
func updateMap() { mkMap.removeAnnotations(mkMap.annotations) mkMap.addAnnotations(yourAnnotationsArray) var union = MKMapRectNull for p in yourAnnotationsArray { // make a small, say, 50meter square for each let pReg = MKCoordinateRegionMakeWithDistance( pa.coordinate, 50, 50 ) // convert it to a MKMapRect let r = mkMapRect(forMKCoordinateRegion: pReg) // union all of those union = MKMapRectUnion(union, r) // probably want to turn on the "sign" for each mkMap.selectAnnotation(pa, animated: false) } // expand the union, using the new
user2285781
source share