2013-08-06 6 views
0

UIViewController 내에서지도보기를 사용하고 있으며 주석을 사용하여 확대 할 기본 위치를 제공했습니다. 그러나 줌이 작동하지 않습니다. 주석은 정상적으로 작동하지만 초기 줌 위치가 작동하지 않습니다.iOS 6지도가 표시되지 않음 lat long location

나는 무엇이 문제의 원인인지 잘 모르겠습니다. 어떤 도움이라도 대단히 감사하겠습니다.

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    MKCoordinateRegion myRegion; 

    //Center 
    CLLocationCoordinate2D center; 
    center.latitude = 39.21516; 
    center.longitude = -76.580806; 

    //Span 
    MKCoordinateSpan span; 
    span.latitudeDelta = 0.02f; 
    span.longitudeDelta = 0.02f; 

    myRegion.center = center; 
    myRegion.span = span; 

    //set mapView 
    [self.mapView setRegion:ascRegion animated:YES]; 

    //Annotation 
    //Create coordinate for annotation 
    CLLocationCoordinate2D theLocation; 
    theLocation.latitude = 39.21516; 
    theLocation.longitude = -76.580806; 

    MyMapAnnotation * myAnnotation = [MyMapAnnotation alloc]; 
    myAnnotation.coordinate = theLocation; 
    myAnnotation.title = @"I am here"; 
    myAnnotation.subtitle = @"This is where I am"; 

    [self.mapView addAnnotation:myAnnotation]; 
} 

답변

1

시도가 this answer을 따라 :

여기 내 코드의

- (void)zoomToFitMapAnnotations:(MKMapView *)mapView { 
    if ([mapView.annotations count] == 0) return; 

    CLLocationCoordinate2D topLeftCoord; 
    topLeftCoord.latitude = -90; 
    topLeftCoord.longitude = 180; 

    CLLocationCoordinate2D bottomRightCoord; 
    bottomRightCoord.latitude = 90; 
    bottomRightCoord.longitude = -180; 

    for(id<MKAnnotation> annotation in mapView.annotations) { 
     topLeftCoord.longitude = fmin(topLeftCoord.longitude, annotation.coordinate.longitude); 
     topLeftCoord.latitude = fmax(topLeftCoord.latitude, annotation.coordinate.latitude); 
     bottomRightCoord.longitude = fmax(bottomRightCoord.longitude, annotation.coordinate.longitude); 
     bottomRightCoord.latitude = fmin(bottomRightCoord.latitude, annotation.coordinate.latitude); 
    } 

    MKCoordinateRegion region; 
    region.center.latitude = topLeftCoord.latitude - (topLeftCoord.latitude - bottomRightCoord.latitude) * 0.5; 
    region.center.longitude = topLeftCoord.longitude + (bottomRightCoord.longitude - topLeftCoord.longitude) * 0.5;  
    region.span.latitudeDelta = fabs(topLeftCoord.latitude - bottomRightCoord.latitude) * 1.1; 

    // Add a little extra space on the sides 
    region.span.longitudeDelta = fabs(bottomRightCoord.longitude - topLeftCoord.longitude) * 1.1; 

    region = [mapView regionThatFits:region]; 
    [mapView setRegion:region animated:YES]; 
} 
+1

감사합니다! 이것은 내가해야 할 일인 것처럼 보입니다. 특히 다음 단계는 더 많은 특수 효과를 포함하고 모든 것을 볼 수 있어야하기 때문입니다. 굉장, 도와 줘서 고마워! – shadonar

+0

@shadonar 문제 없습니다. 나는 몇 주 전에 비슷한 일을했다. 사람들이 쉽게 볼 수 있도록 내가 연결된 대답을 Upvote. –