2012-12-20 3 views
1

오버뷰보기 아래의지도 주석을 확대해야합니다.오버뷰보기 아래의 MapView 주석을 줌하는 방법?

Im this method을 사용하여 2 개의 주석을 확대/축소합니다.

내가 오버 배치보기 아래의 2 주석을 맞게 할 수있는 방법을 찾을 수 없습니다 이유는지도 센터가 숨겨집니다 설정 아래 핀

  • 을 숨길지도의 edgePadding 설정

    • 아래쪽 핀
    • latitudeDelta를 설정하면 핀이 수평으로 평행 할 경우 병렬 연결이 필요 없어 지거나 다른 케이스가 더러워집니다.

    내가 놓친이 문제에 대한 우아한 해결책이 있는지 궁금합니다.

    이 오버레이는 주석 선을 숨 깁니다

    The problem

    , 나는 내가 첫 번째 문제에 대한 해결책이있는 경우이 해결 될 수있는 것 같아요.

  • 답변

    0

    오버레이에서 터치 포인트를 원한다면 오버레이에 대해 사용자 인터페이스를 사용하지 않도록 설정하십시오.

    줌 레벨을 설정하기 위해 포인트를 플롯 한 후 몇 가지 조정을했습니다. lat longs의 평균을 계산 한 다음 overlay의 크기에 따라 lat long을 조정할 수 있습니다. 여기에 내가했던 일이야 :

      float latAvg,longAvg; 
    
    
          latAvg = (location1.latitude + location.latitude)/2; 
          longAvg = (location1.longitude + location.longitude)/2; 
          MKCoordinateSpan span;// = MKCoordinateSpanMake(0.006, 0.006); 
    
          span.latitudeDelta = fabs(location1.latitude - location.latitude); 
          span.longitudeDelta = fabs(location1.longitude - location.longitude); 
    
    
    //Then adjust the lat longs delta according to your need. 
    
          span.latitudeDelta = span.latitudeDelta + 0.0010; 
          span.longitudeDelta = span.longitudeDelta + 0.0010; 
    
          CLLocationCoordinate2D locationLatlng; 
          locationLatlng.latitude = latAvg; 
          locationLatlng.longitude = longAvg; 
    
          MKCoordinateRegion viewRegion = MKCoordinateRegionMake(locationLatlng, span); 
    
    
          [map setRegion:viewRegion animated:YES]; 
    
          [map regionThatFits:viewRegion]; 
    
    3

    은 아마 당신은 주석을위한 완벽한 적합을 처리하기 위해이 코드를 시도해야합니다 :

    - (void)zoomMapViewToFitAnnotations:(MKMapView *)mapView animated:(BOOL)animated 
    { 
        NSArray *annotations = mapView.annotations; 
        int count = [mapView.annotations count]; 
        if (count == 0) { return; } //return if no annotations 
    
        //convert NSArray of id <MKAnnotation> into an MKCoordinateRegion that can be used to set the map size 
        //can't use NSArray with MKMapPoint because MKMapPoint is not an id 
        MKMapPoint points[count]; //C array of MKMapPoint struct 
        for(int i=0; i<count; i++) //load points C array by converting coordinates to points 
        { 
         CLLocationCoordinate2D coordinate = [(id <MKAnnotation>)[annotations objectAtIndex:i] coordinate]; 
         points[i] = MKMapPointForCoordinate(coordinate); 
        } 
        //create MKMapRect from array of MKMapPoint 
        MKMapRect mapRect = [[MKPolygon polygonWithPoints:points count:count] boundingMapRect]; 
        //convert MKCoordinateRegion from MKMapRect 
        MKCoordinateRegion region = MKCoordinateRegionForMapRect(mapRect); 
    
        //add padding so pins aren't scrunched on the edges 
        region.span.latitudeDelta *= ANNOTATION_REGION_PAD_FACTOR; 
        region.span.longitudeDelta *= ANNOTATION_REGION_PAD_FACTOR; 
        //but padding can't be bigger than the world 
        if(region.span.latitudeDelta > MAX_DEGREES_ARC) { region.span.latitudeDelta = MAX_DEGREES_ARC; } 
        if(region.span.longitudeDelta > MAX_DEGREES_ARC){ region.span.longitudeDelta = MAX_DEGREES_ARC; } 
    
        //and don't zoom in stupid-close on small samples 
        if(region.span.latitudeDelta < MINIMUM_ZOOM_ARC) { region.span.latitudeDelta = MINIMUM_ZOOM_ARC; } 
        if(region.span.longitudeDelta < MINIMUM_ZOOM_ARC) { region.span.longitudeDelta = MINIMUM_ZOOM_ARC; } 
        //and if there is a sample of 1 we want the max zoom-in instead of max zoom-out 
        if(count == 1) 
        { 
         region.span.latitudeDelta = MINIMUM_ZOOM_ARC; 
         region.span.longitudeDelta = MINIMUM_ZOOM_ARC; 
        } 
        [mapView setRegion:region animated:animated]; 
    } 
    

    그래서, 당신은 패딩, 최대 수준 아크 및 최소 줌 호를 정의해야합니다. 예를 들어. ,

    #define MINIMUM_ZOOM_ARC 0.05 //approximately 1 miles (1 degree of arc ~= 69 miles) 
    #define ANNOTATION_REGION_PAD_FACTOR 1.25 
    #define MAX_DEGREES_ARC 360 
    

    바라건대, 당신은 그것을 좋아할 것이다 건배

    +0

    그게 꽤 좋은를하지만 여전히 이상 배치보기 아래 주석에 맞지 않는 :이 belike한다. 그것은 현재 코드와 같은 결과를 가지고 있습니다. –

    +0

    설명보기와 같이보기가 작동합니까? – IKQ

    +0

    투명한 검정색 오버뷰보기는 IB의지도 뷰 위에 놓입니다. –