objective c - Zooming out to see all the pins in MapView -
objective c - Zooming out to see all the pins in MapView -
i have 20-30 pins displayed on mapview command , want zoom out pins visible. here code:
mkcoordinateregion part = mkcoordinateregionmakewithdistance([mp coordinate],500000, 500000); [mv setregion:region animated:yes];
how can that?
/** * center map on area covering annotations on map. */ - (void)recentermap { nsarray *coordinates = [self.mapview valueforkeypath:@"annotations.coordinate"]; // minimum , maximum coordinate cllocationcoordinate2d maxcoord = {-90.0f, -180.0f}; cllocationcoordinate2d mincoord = {90.0f, 180.0f}; for(nsvalue *value in coordinates) { cllocationcoordinate2d coord = {0.0f, 0.0f}; [value getvalue:&coord]; if(coord.longitude > maxcoord.longitude) { maxcoord.longitude = coord.longitude; } if(coord.latitude > maxcoord.latitude) { maxcoord.latitude = coord.latitude; } if(coord.longitude < mincoord.longitude) { mincoord.longitude = coord.longitude; } if(coord.latitude < mincoord.latitude) { mincoord.latitude = coord.latitude; } } // create part mkcoordinateregion part = {{0.0f, 0.0f}, {0.0f, 0.0f}}; region.center.longitude = (mincoord.longitude + maxcoord.longitude) / 2.0; region.center.latitude = (mincoord.latitude + maxcoord.latitude) / 2.0; // calculate span region.span.longitudedelta = maxcoord.longitude - mincoord.longitude; region.span.latitudedelta = maxcoord.latitude - mincoord.latitude; // center map on part [self.mapview setregion:region animated:yes]; }
objective-c mapkit
Comments
Post a Comment