Friday, July 16, 2010

Adding images to map Annotation

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:
(id )annotation {
if (annotation == mapView.userLocation) return nil;

UIImage *anImage = nil;
if([[annotation title] isEqualToString:@"type1"])
{
anImage=[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"type1.png" ofType:nil]];
}
else if([[annotation title] isEqualToString:@"type2"])
{
anImage=[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"type2.png" ofType:nil]];
}
else if([[annotation title] isEqualToString:@"type3"])
{
anImage=[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"type3.png" ofType:nil]];
}
else if([[annotation title] isEqualToString:@"type4"])
{
anImage=[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"type4.png" ofType:nil]];
}

MKAnnotationView *anView=(MKAnnotationView*)[mapView
dequeueReusableAnnotationViewWithIdentifier:@"annotation"];

if(anView==nil){
anView=[[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"annotation"] autorelease];
}
anView.image = anImage;
anView.annotation=annotation;
anView.canShowCallout=YES;
if(tag==0){
anView.rightCalloutAccessoryView=[UIButton buttonWithType:UIButtonTypeDetailDisclosure];
}
return anView;
}

No comments:

FEEDJIT Live