Как я могу создать эффект масштаба на основе расстояния от точки - PullRequest
0 голосов
/ 17 февраля 2012

Я делаю проект дополненной реальности и хочу создать эффект увеличения изображения: я хочу, чтобы это изображение увеличивалось при уменьшении расстояния.

  1. У меня уже есть расстояние.
  2. У меня есть изображение.
  3. У меня есть максимальное расстояние, при котором включается зум.

1 Ответ

0 голосов
/ 17 февраля 2012

Следующий код используется для увеличения в качестве расстояния до булавки.

-(void) centerMap 

{
    MKCoordinateRegion region;
    CLLocationDegrees maxLat = -90;
    CLLocationDegrees maxLon = -180;
    CLLocationDegrees minLat = 120;
    CLLocationDegrees minLon = 150;
    NSArray *temp=self.AS;
//  NSArray *temp=[NSArray arrayWithArray:[NSArray arrayWithArray:[reports objectAtIndex:0]]];
    for (int i=0; i<[temp count];i++) {
        Place* home = [[[Place alloc] init] autorelease];
        home.latitude = [[[temp objectAtIndex:i] valueForKey:@"latitude"]floatValue];
        home.longitude =[[[temp objectAtIndex:i] valueForKey:@"longitude"]floatValue];

        PlaceMark* from = [[[PlaceMark alloc] initWithPlace:home] autorelease];     

        CLLocation* currentLocation = (CLLocation*)from ;
        if(currentLocation.coordinate.latitude > maxLat)
            maxLat = currentLocation.coordinate.latitude;
        if(currentLocation.coordinate.latitude < minLat)
            minLat = currentLocation.coordinate.latitude;
        if(currentLocation.coordinate.longitude > maxLon)
            maxLon = currentLocation.coordinate.longitude;
        if(currentLocation.coordinate.longitude < minLon)
            minLon = currentLocation.coordinate.longitude;

        region.center.latitude     = (maxLat + minLat) / 2;
        region.center.longitude    = (maxLon + minLon) / 2;
        region.span.latitudeDelta  =  maxLat - minLat;
        region.span.longitudeDelta = maxLon - minLon;
    }
    [mapView setRegion:region animated:YES];

}

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

    if (annotation == mapView.userLocation) 
        return nil;

    MKPinAnnotationView *pin = (MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier: @"asdf"];

    if (pin == nil)
        pin = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier: @"asdf"] autorelease];
    else
        pin.annotation = annotation;
    pin.userInteractionEnabled = YES;
    UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
    [disclosureButton setFrame:CGRectMake(0, 0, 30, 30)];

    pin.rightCalloutAccessoryView = disclosureButton;
    pin.pinColor = MKPinAnnotationColorRed;
    //pin.animatesDrop = YES;
    [pin setEnabled:YES];
    [pin setCanShowCallout:YES];
    return pin;

}

Этот код может помочь в создании нового приложения,

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...