ios - Fitting annotations on a MKMapView while keeping user position centered -



ios - Fitting annotations on a MKMapView while keeping user position centered -

i'm trying fit annotations on mkmapview while keeping current user position in center of map.

there many references[1][2] on how zoom out part fit annotations on map adjust current center position e.g. if annotations located east of current user position, adjust current user position moved left of map.

how can zoom map out fit annotations shown keep users current position in center of map?

refs:

[1] zooming mkmapview fit annotation pins?

[2] - (void)showannotations:(nsarray *)annotations animated:(bool)animated ns_available(10_9, 7_0);

i found solution reliable , @anna suggested might ok solution.

this method (implemented method of inherited mkmapview

- (void)fitannotationskeepingcenter { cllocation *centerlocation = [[cllocation alloc] initwithlatitude:self.centercoordinate.latitude longitude:self.centercoordinate.longitude]; // starting distance (do not zoom less this) cllocationdistance maxdistance = 350; (id <mkannotation> vehicleannotation in [self annotations]) { cllocation *annotationlocation = [[cllocation alloc] initwithlatitude:vehicleannotation.coordinate.latitude longitude:vehicleannotation.coordinate.longitude]; maxdistance = max(maxdistance, [centerlocation distancefromlocation:annotationlocation]); } mkcoordinateregion fittedregion = mkcoordinateregionmakewithdistance(centerlocation.coordinate, maxdistance * 2, maxdistance * 2); fittedregion = [self regionthatfits:fittedregion]; fittedregion.span.latitudedelta *= 1.2; fittedregion.span.longitudedelta *= 1.2; [self setregion:fittedregion animated:yes]; }

ios iphone mkmapview mkuserlocation

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -