ios - iPhone MKMapView: set map region to show all pins on map -


i'm trying set map region (center , span) map shows pin-annotations @ same time.

i'm having trouble converting long/lat coordinates nsstring double, resp. make calculations them. here code i'm using:

- (void)updatememberpins{  //calculate new region show on map double center_long = 0.0f; double center_lat = 0.0f; double max_long = 0.0f; double min_long = 0.0f; double max_lat = 0.0f; double min_lat = 0.0f;  (member *member in members) {      //find min , max values     if ([member.loclat doublevalue] > max_lat) {max_lat = [member.loclat doublevalue];}     if ([member.loclat doublevalue] < min_lat) {min_lat = [member.loclat doublevalue];}     if ([member.loclong doublevalue] > max_long) {max_long = [member.loclong doublevalue];}     if ([member.loclong doublevalue] < min_long) {min_long = [member.loclong doublevalue];}      //sum long , lang average later     center_lat = center_lat + [member.loclat doublevalue];     center_long = center_long + [member.loclong doublevalue]; }  //calculate average long / lat center_lat = center_lat / [members count]; center_long = center_long / [members count];  nslog(@"center long: %d, center lat: %d", center_long, center_lat); nslog(@"max_long: %d, min_long: %d, max_lat: %d, min_lat: %d", max_long, min_long, max_lat, min_lat);  //create new region , set map cllocationcoordinate2d coord = {latitude: center_lat, longitude: center_long}; mkcoordinatespan span = mkcoordinatespanmake(abs(max_lat) + abs(min_lat), abs(max_long) + abs(min_long)); mkcoordinateregion region = {coord, span}; [resultmapview setregion:region];  //remove pins map [resultmapview removeannotations:resultmapview.annotations];  //show member pins (id member in members) {     [resultmapview addannotation:(member *) member]; } 

}

the result of log-output is:

center long: -1946827116, center lat: 1075651472

max_long: -6267216, min_long: 1076018553, max_lat: 0, min_lat: 0

i think problem comes (wrongly) converting values nsstring double, cannot find way make work... format of location-strings '43.5686473'.

any hints? cheerz

to show double value in nslog(), should use %f, instead of %d change nslog() part this:

nslog(@"center long: %f, center lat: %f", center_long, center_lat); nslog(@"max_long: %f, min_long: %f, max_lat: %f, min_lat: %f", max_long, min_long, max_lat, min_lat); 

also, using region mkmapview simpler making own. once it's set zoom ratio, need dynamically move around map different coordinates.

mkcoordinateregion region = self.mapview.region; region.center = centercoordinate; region.span.longitudedelta /= ratiozoommax; // bigger value, closer map view region.span.latitudedelta /= ratiozoommax; [self.mapview setregion:region animated:yes]; // choose if want animate or not 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -