Uncenter MkMapView

głosy
0

Próbuję „uncenter” widoku mapy i usunąć wszystkie adnotacje. Powodem tego jest to, że MapView będą wykorzystywane przez różnych kontrolerów widoku, aby wyświetlać różne adnotacje i lokalizacje. Co się teraz dzieje jest to, że używam „Usuń adnotacji” metody i je usuwa, ale mapa pozostaje skupione na miejscu, a więc kiedy nowe adnotacje przyjść, to nie rusza. Czy istnieje sposób, aby przywrócić ten region, a jeśli tak, to jaką wartość zresetować go. Próbowałem zero, zero, a niektóre obliczona wartość, ale „animacja core” mówi, że są nieważne. jak mogę dostać to, aby pomniejszyć iz powrotem na moich nowych adnotacji?

Oto niektóre kodu

-(void)recenterMap {

NSArray *coordinates = [_mapView valueForKeyPath:@annotations.coordinate];
CLLocationCoordinate2D maxCoord = {-90.0f, -180.0f};
CLLocationCoordinate2D minCoord = {90.0f, 180.0f};

//NSLog(@%@, [coordinates description]);

for (NSValue *value in coordinates) {
    CLLocationCoordinate2D coord = {0.0f, 0.0f};
    [value getValue: &coord];

    if(coord.longitude > maxCoord.longitude) {
        maxCoord.longitude = coord.longitude;
    }

    if(coord.latitude > maxCoord.latitude){

        maxCoord.latitude = coord.latitude;
    }

    if(coord.longitude < minCoord.longitude){
        minCoord.longitude = coord.longitude;
    }

    if(coord.latitude < minCoord.latitude){
        minCoord.latitude = coord.latitude;
    }
}


MKCoordinateRegion region = {{0.0f, 0.0f}, {0.0f, 0.0f}};
region.center.longitude = (minCoord.longitude + maxCoord.longitude) / 2.0;
region.center.latitude = (minCoord.latitude + maxCoord.latitude) / 2.0;
region.span.longitudeDelta = maxCoord.longitude - minCoord.longitude;
region.span.latitudeDelta = maxCoord.latitude - minCoord.latitude;


[_mapView setRegion: region animated: YES];
}

Ów Methos Wyśrodkuj używam

- (MKAnnotationView *)mapView: (MKMapView *)mapView viewForAnnotation: (id <MKAnnotation>)annotation{

MKAnnotationView *view = nil;
if(annotation != mapView.userLocation){

    Annotation *schoolAnn = (Annotation*)annotation;
    view = [self.mapView dequeueReusableAnnotationViewWithIdentifier:@schoolLoc];
    if(nil == view){
        view = [[[MKPinAnnotationView alloc] initWithAnnotation:schoolAnn     reuseIdentifier:@schoolLoc]autorelease];
    }

    [(MKPinAnnotationView *)view setAnimatesDrop:YES];
    [view setCanShowCallout:YES];

}
else { 
    [self recenterMap];
}

return view;
}

Ten „inny” kawałek czeka aż Blue Marble krople następnie wyśrodkowany mapę. Mam problem z tym jest to, że kiedy wrócę do poprzedniego widoku kontrolera i usunąć wszystkie adnotacje, więc kiedy wrócę w lokalizacji użytkownika (z jakiegoś powodu) nie pop widok. Jak uzyskać ten pop widok?

Z góry dzięki chłopaki

Utwórz 08/01/2010 o 13:03
źródło użytkownik
W innych językach...                            


1 odpowiedzi

głosy
0

Dostał pierwszą część, czyni ją pomniejszyć ponownie tylko przez wywołanie funkcji i wykonany, że zestaw ten region się być nad USA.

-(void)unCenterMap{

MKCoordinateRegion region2 = {{0.0f, 0.0f}, {0.0f, 0.0f}};
region2.center.longitude = (-98.151855); //coordinate for approximately the center of the US
region2.center.latitude = 39.402244;
region2.span.longitudeDelta = 3.0;
region2.span.latitudeDelta = 3.0;


[_mapView setRegion: region2 animated: YES];

}

Druga część wciąż mnie zdumiewa, jak mogę, że lokalizacja pop ponownie?

Odpowiedział 11/01/2010 o 10:24
źródło użytkownik

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more