all I need to show multiple annotations within a mapview and zoom to show all this annotations. I have the code fore that
MKMapRect zoomRect = MKMapRectNull;
int i = 0;
for (Post *post in _allPostsToList) {
if (((post.location2D.latitude == 0.0f)&&(post.location2D.longitude == 0.0f))||(!CLLocationCoordinate2DIsValid(post.location2D))) {
i++;
continue;
}
MyAnnotation *annotation = [[MyAnnotation alloc] initWithpost:post];
annotation.tag = i++;
[mapView addAnnotation:annotation];
MKMapPoint annotationPoint = MKMapPointForCoordinate(annotation.coordinate);
MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0, 0);
zoomRect = (MKMapRectIsNull(zoomRect))?pointRect:MKMapRectUnion(zoomRect, pointRect);
}
[mapView setVisibleMapRect:zoomRect animated:YES];
it works fine but, I need one more thing with this, Needs user location blue bubble in the center of the map with showing all the above annotation. How to do this. I tried this
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
MKMapRect zoomRect = mapView.visibleMapRect;
MKMapPoint annotationPoint = MKMapPointForCoordinate(newLocation.coordinate);
MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0, 0);
zoomRect = (MKMapRectIsNull(zoomRect))?pointRect:MKMapRectUnion(zoomRect, pointRect);
[mapView setVisibleMapRect:zoomRect animated:YES];
[manager stopUpdatingLocation];
}
Its working But its not centering user location How to dow this. Can anyone solve this problem
Just a bet; what about accessing your mapView's region and try to set the new center: