I am developing an application using MKMapView . I have a few annotations. Now I want to display a custom annotation image for the pin. I created my own class for MapViewAnnotation.
I get a few lat-long from api and showing like this:
[self.map_parking addAnnotations:[self createAnnotations]]
- (NSMutableArray *)createAnnotations { NSMutableArray *annotations = [[NSMutableArray alloc] init]; for (NSDictionary *row in arrfinal) { NSNumber *latitude = [row objectForKey:@"latitude"]; NSNumber *longitude = [row objectForKey:@"longitude"]; NSString *title = [row objectForKey:@"title"]; NSString *subtitle = [row objectForKey:@"subtitle"]; NSString *rate = [row objectForKey:@"rate"];
To display the annotation, I use the link to this method from this link: MKMapView: instead of the Pin annotation, a custom view
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation { MKAnnotationView *pinView = nil; if(annotation != map_parking.userLocation) { static NSString *defaultPinID = @"com.invasivecode.pin"; pinView = (MKAnnotationView *)[map_parking dequeueReusableAnnotationViewWithIdentifier:defaultPinID]; if ( pinView == nil ) pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID]; pinView.canShowCallout = YES; //pinView.animatesDrop = YES; for (int i=0; i<arrrates.count; i++) { if ([[arrrates objectAtIndex:i] isEqualToString:@"0.00"]) { pinView.image = [UIImage imageNamed:@"marker1"]; } else if ([[arrrates objectAtIndex:i] isEqualToString:@"100.71"]) { pinView.image = [UIImage imageNamed:@"marker2"]; } else { pinView.image = [UIImage imageNamed:@"marker3"]; } } } else { [map_parking.userLocation setTitle:@"I am here"]; } return pinView; }
In this if-else method, the condition works well, but all the pinout images that were the last condition.
ios objective-c mkmapview mkannotation
Bhavin Ramani Feb 26 '16 at 9:24 2016-02-26 09:24
source share