iphone - MapKit: How can I pan and zoom to fit all my annotations? -


so i've got bunch of annotations spread out on map... dandy. need able set map's position , zoom fit perfectly. how can this?

@interface mkmapview (zoomtofit)  - (void)zoomtofitoverlays; //animation defaults yes - (void)zoomtofitoverlay:(id<mkoverlay>)anoverlay; - (void)zoomtofitoverlays:(nsarray *)someoverlays;  - (void)zoomtofitoverlaysanimated:(bool)animated; - (void)zoomtofitoverlay:(id<mkoverlay>)anoverlay animated:(bool)animated; - (void)zoomtofitoverlays:(nsarray *)someoverlays animated:(bool)animated;  - (void)zoomtofitoverlays:(nsarray *)someoverlays animated:(bool)animated insetproportion:(cgfloat)insetproportion; //inset 0->1, defaults in other methods .1 (10%)  @end  @implementation mkmapview (zoomtofit)   #pragma mark - #pragma mark zoom fit  - (void)zoomtofitoverlays {     [self zoomtofitoverlaysanimated:yes]; }  - (void)zoomtofitoverlay:(id<mkoverlay>)anoverlay {     [self zoomtofitoverlay:[nsarray arraywithobject:anoverlay] animated:yes]; }  - (void)zoomtofitoverlays:(nsarray *)someoverlays {     [self zoomtofitoverlays:someoverlays animated:yes]; }  - (void)zoomtofitoverlaysanimated:(bool)animated {     [self zoomtofitoverlays:self.overlays animated:animated]; }  - (void)zoomtofitoverlay:(id<mkoverlay>)anoverlay animated:(bool)animated {     [self zoomtofitoverlays:[nsarray arraywithobject:anoverlay] animated:yes];   }  - (void)zoomtofitoverlays:(nsarray *)someoverlays animated:(bool)animated {     [self zoomtofitoverlays:someoverlays animated:animated insetproportion:.1]; }  - (void)zoomtofitoverlays:(nsarray *)someoverlays animated:(bool)animated insetproportion:(cgfloat)insetproportion {     //check     if ( !someoverlays || !someoverlays.count ) {         return;     }      //union     mkmaprect maprect = mkmaprectnull;     if ( someoverlays.count == 1 ) {         maprect = ((id<mkoverlay>)someoverlays.lastobject).boundingmaprect;     } else {         ( id<mkoverlay> anoverlay in someoverlays ) {             maprect = mkmaprectunion(maprect, anoverlay.boundingmaprect);         }     }      //inset     cgfloat inset = (cgfloat)(maprect.size.width*insetproportion);     maprect = [self maprectthatfits:mkmaprectinset(maprect, inset, inset)];      //set     mkcoordinateregion region = mkcoordinateregionformaprect(maprect);     [self setregion:region animated:animated]; }  @end 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -