Iphone MapView: Pin за анотация - различен цвят

Моля за съвет при решаването на този проблем:

Извличам XML файл за показване на Pins в моя MapView. При друг метод показвам текущата си позиция на картата:

-(void)setPOIs {

NSLog(@"insert POIs");

int x = 0;

while (x < [res count]) {

    CLLocationCoordinate2D c;
    NSString *latitude = [[res objectAtIndex:x] objectForKey:@"latitude"];
    NSString *longitude = [[res objectAtIndex:x] objectForKey:@"longitude"];
    c.latitude = [latitude doubleValue];
    c.longitude = [longitude doubleValue];
    GPSAnnotation *annotation = [[GPSAnnotation alloc] initWithCoordinate:c];
    annotation.mTitle=[[res objectAtIndex:x] objectForKey:@"ordiname"];
    annotation.currentPoint = [NSNumber numberWithInt:[[[res objectAtIndex:x] objectForKey:@"tierarztid"] intValue]];
    annotation.currentRow = [res objectAtIndex:x];
    [mapViewOutlet addAnnotation:annotation];
    [annotation release];

    NSLog(@"latitude setPOIs: %@", latitude);
    x++;
}   

[self showOwn];

}

-(void)showOwn {

CLLocationCoordinate2D c;
c.latitude = location.latitude;
c.longitude = location.longitude;
GPSAnnotation *annotation1 = [[GPSAnnotation alloc] initWithCoordinate:c];
annotation1.mTitle= @"Ihr Standort";
[mapViewOutlet addAnnotation:annotation1];
[annotation1 release];    

}

Тук показвам щифтовете:

- (MKAnnotationView *)mapView:(MKMapView *)mapViewOutlet viewForAnnotation:(GPSAnnotation *)annotation {

int postag = 0;
//int row = 0;

MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
annView.pinColor = MKPinAnnotationColorGreen;
UIButton *myDetailButton = [UIButton buttonWithType:UIButtonTypeCustom];
myDetailButton.frame = CGRectMake(0, 0, 23, 23);
myDetailButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
myDetailButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;


    // Set the image for the button
[myDetailButton setImage:[UIImage imageNamed:@"button_right.png"] forState:UIControlStateNormal];
[myDetailButton addTarget:self action:@selector(showLinks:) forControlEvents:UIControlEventTouchUpInside]; 


if ([[annotation title] isEqualToString:@"Current Location"]) {
    postag = 99999;
} else {
    postag = [annotation.currentPoint intValue];

} 



myDetailButton.tag  = postag;

// Set the button as the callout view
annView.rightCalloutAccessoryView = myDetailButton;

annView.animatesDrop=NO;
annView.canShowCallout = YES;
annView.calloutOffset = CGPointMake(-5, 5);


return annView;

[annView release];

}

Какво мога да направя, за да покажа персонализирано изображение за текущата си позиция - и/или да не покажа бутон за разкриване?


person Bosstone    schedule 16.03.2011    source източник
comment
дубликат? stackoverflow.com/questions/5329575/   -  person GendoIkari    schedule 17.03.2011


Отговори (2)


благодаря за обратната връзка! Реших, като просто адаптирах оператор if... else

- (MKAnnotationView *)mapView:(MKMapView *)mapViewOutlet viewForAnnotation:(GPSAnnotation *)annotation {

int postag = 0;
//int row = 0;

MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
annView.pinColor = MKPinAnnotationColorGreen;
UIButton *myDetailButton = [UIButton buttonWithType:UIButtonTypeCustom];
myDetailButton.frame = CGRectMake(0, 0, 23, 23);
myDetailButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
myDetailButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;


if ([[annotation title] isEqualToString:@"Ihr Standort"]) {
    postag = 99999;
    UIImage *annotationImage = [UIImage imageNamed:@"07-map-marker.png"];
    annView.image = annotationImage;
} else {
    postag = [annotation.currentPoint intValue];
    [myDetailButton setImage:[UIImage imageNamed:@"button_right.png"] forState:UIControlStateNormal];
    [myDetailButton addTarget:self action:@selector(showLinks:) forControlEvents:UIControlEventTouchUpInside]; 

} 



myDetailButton.tag  = postag;

// Set the button as the callout view
annView.rightCalloutAccessoryView = myDetailButton;

annView.animatesDrop=NO;
annView.canShowCallout = YES;
annView.calloutOffset = CGPointMake(-5, 5);


return annView;

[annView release];

}

BR,

Стефан

person Bosstone    schedule 17.03.2011

Вместо да използвате MKPinAnnotationView използвайте MKAnnotationView. MKPinAnnotationView е подклас на MKAnnotationView. MKPinAnnotationView ще показва САМО щифтове. MKAnnotationView има свойство за изображение, което можете да настроите да показва различно изображение вместо щифт.

Редът от код, който показва бутона за разкриване, е вашата rightCalloutAccessoryView инструкция. Извадете това и разкриването на подробности в допълнителното описание ще изчезне.

person Walter    schedule 16.03.2011