views:

264

answers:

1

Hello,

how can I zoom the map on my userLocation automatically in my app? I have the following code to zomm in the map but i must zoom on the userLocation and the following code zooms always to africa?

MKCoordinateRegion zoomIn = mapView.region;
    zoomIn.span.latitudeDelta *= 0.2;
    zoomIn.span.longitudeDelta *= 0.2;
    zoomIn.center.latitude = mapView.userLocation.location.coordinate.latitude;
    zoomIn.center.longitude = mapView.userLocation.location.coordinate.longitude;
    [mapView setRegion:zoomIn animated:YES];
A: 

OK i solved the problem, with the following delegate Method:

-(void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views{
    for(MKAnnotationView *annotationView in views) {
        if(annotationView.annotation == mv.userLocation){
            MKCoordinateRegion region;
            MKCoordinateSpan span;

            span.latitudeDelta=0.9;
            span.longitudeDelta=0.9;

            CLLocationCoordinate2D location =mv.userLocation.coordinate;

            location = mv.userLocation.location.coordinate;

            region.span = span;
            region.center = location;
            [mv setRegion:region animated:TRUE];
            [mv regionThatFits:region];
        }
    }
}
Marco