Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 30th, 2012  |  syntax: None  |  size: 1.06 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Center MKMapView on userLocation (initially) - only works on iPhone 4?
  2. // Center map on user location (initially)
  3. - (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
  4.     for(MKAnnotationView *annotationView in views) {
  5.         if(annotationView.annotation == parishMap.userLocation) {
  6.             MKCoordinateRegion region;
  7.             MKCoordinateSpan span;
  8.  
  9.             span.latitudeDelta=0.03;
  10.             span.longitudeDelta=0.03;
  11.  
  12.             CLLocationCoordinate2D location=parishMap.userLocation.coordinate;
  13.  
  14.             location = parishMap.userLocation.location.coordinate;
  15.  
  16.             region.span=span;
  17.             region.center=location;
  18.  
  19.             [parishMap setRegion:region animated:TRUE];
  20.             [parishMap regionThatFits:region];
  21.         }
  22.     }
  23. }
  24.        
  25. [mapView setCenterCoordinate:location animated:YES];
  26.        
  27. MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(location, 0.03, 0.03);
  28.     MKCoordinateRegion adjustedRegion = [mapView regionThatFits:viewRegion];
  29.  
  30.     [mapView setRegion:adjustedRegion animated:YES];