Custom Annotation not showing all
- by funatsg
Okay, i have a number of pins on the mapkit. These pins showing different types of attractions. (E.g Parks, Farms and etc)
I want to add custom images for these different types of pin. Parks have a park image and vice versa.
However, when i added in, not all the images are showing successfully. For example, in parks, it should have 5 pins, but the image only came up in 2 pins, whereas other 3 is in default red pins.
But if i used colours to differentiate them.
For example, [pinsetPinColor:MKPinAnnotationColorGreen];
It works! Anyone knows what is the problem?
Relevant codes below. Tell me if you need more. thanks!
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
if ([annotation isKindOfClass:MKUserLocation.class]) {
//user location view is being requested,
//return nil so it uses the default which is a blue dot...
return nil;
}
//NSLog(@"View for Annotation is called");
MKPinAnnotationView *pin=[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:nil];
pin.userInteractionEnabled=TRUE;
MapEvent* event = (MapEvent*)annotation;
NSLog(@"thetype: %@", event.thetype);
if ([event.thetype isEqualToString:@"adv"]) {
//[pin setPinColor:MKPinAnnotationColorGreen];
pin.image = [UIImage imageNamed:@"padv.png"];
}
else if ([event.thetype isEqualToString:@"muse"]){
//[pin setPinColor:MKPinAnnotationColorPurple];
pin.image = [UIImage imageNamed:@"pmuse.png"];
}
else if ([event.thetype isEqualToString:@"nightlife"]){
pin.image = [UIImage imageNamed:@"pnight.png"];
}
else if ([event.thetype isEqualToString:@"parks"]){
pin.image = [UIImage imageNamed:@"ppark.png"];
}
else if ([event.thetype isEqualToString:@"farms"]){
pin.image = [UIImage imageNamed:@"pfarm.png"];
}
else {
[pin setPinColor:MKPinAnnotationColorRed];
}
pin.canShowCallout = YES;
pin.animatesDrop = YES;
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self action:@selector(clickAnnotation:) forControlEvents:UIControlEventTouchUpInside];
[rightButton setTitle:event.uniqueID forState:UIControlStateNormal];
pin.rightCalloutAccessoryView = rightButton;
return pin;
}