I am trying to customize a map displaying different contact colors depending on the type / class of the location in question. I know this is a pretty common thing, but I'm having trouble getting a viewForAnnotation delegate to constantly update / set the color of the pin.
I have a showThisLocation function, which basically goes through the AddressAnnotations list, and then based on the annotation class (bus stop, hospital, etc.). I have installed
if( myClass == 1){
[defaults setObject:@"1" forKey:@"currPinColor"];
[defaults synchronize];
NSLog(@"Should be %@!", [defaults objectForKey:@"currPinColor"]);
} else if( myClass ==2 ){
[defaults setObject:@"2" forKey:@"currPinColor"];
[defaults synchronize];
NSLog(@"Should be %@!", [defaults objectForKey:@"currPinColor"]);
}
[_mapView addAnnotation:myCurrentAnnotation];
then my viewForAnnotation delegate looks like this:
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
if( annotation == mapView.userLocation ){ return nil; }
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
MKPinAnnotationView *annView = nil;
annView = (MKPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:@"currentloc"];
if( annView == nil ){
annView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
}
annView.pinColor = [defaults integerForKey:@"currPinColor"];
NSLog(@"Pin color: %d", [defaults integerForKey:@"currPinColor"]);
annView.animatesDrop=TRUE;
annView.canShowCallout = YES;
annView.calloutOffset = CGPointMake(-5, 5);
return annView;
}
, , NSLog "if" , , , , . , , "if", .
, NSUserDefaults , MKAnnotation, "currentPinColor", "currentPinColor", "currentPinColor" , , "currentPinColor" MKAnnotation. , ,
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MyCustomMKAnnotation>)annotation
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
, MyCustomMKAnnotation .
/ MyCustomMKAnnotation, , pinColor. , .