Custom Pin Issue

Joined
Mar 8, 2011
Messages
4
Reaction score
0
Points
1
So I have this problem. I'm trying to add a bunch of annotations to my MapView, of various different colors. I've implemented the correct protocols, and I'm calling the addAnnotation method in the map view object. The issue is that either none or very few annotations appear (I'm not sure what the factor that determines this change is).

I have this method called updateNodes that is being called regularly (about every 5 seconds). This method goes through an array of custom objects I've made called, Party objects. In my main View Controller I have a property called "currentParty" which the current party points through. The objective of this method is pretty much to loop through each party, adding it to the map, and then stop.

Theoretically this is all working to the program. There are around 8 Party objects at a time in the array, and each object has the "addAnnotation" method called on it (I've tested it with a few NSLog statements). But the error is that the annotations themselves aren't being added to the map. I've overridden the viewForAnnotation method, but that method for some reason is being delayed when it's getting called, and it's only getting called around once, when I expected it to be getting called each time the addAnnotation method is called (which is about 8 times). However it is only called once (again, tested with a print statement at the top of the method).

The code is below:

Code:
//Main view controller
- (void)viewDidLoad{
    currentParty = [[Party alloc] init];
    [ViewController instantiatePartyArray];
    initialPinAlreadyAdded = NO;
    NSLog(@"View Did Load Called");
    [super viewDidLoad];
	manager = [[CLLocationManager alloc] init];     //Instantiate CLLocationManager
         //Array that holds all parties. Should be populated from the database
    manager.desiredAccuracy = kCLLocationAccuracyBest;  //Best accuracy
    manager.delegate = self;            //Delegate the manager to affect this View Controller
    self.map.delegate = self;
    [manager startUpdatingLocation];     //Triangulate location
    NSLog(@"Triangulation Started");
    MKCoordinateSpan span;
    span.latitudeDelta = 0.01;      //10 km up and down
    span.longitudeDelta = 0.01;     //10 km side to side
    MKCoordinateRegion region;
    region.span = span;
    region.center = startingUserLocation.coordinate;
    if(loc.coordinate.latitude != 0 && loc.coordinate.longitude != 0){
        [map setRegion: region animated: YES];
        NSLog(@"Setting Region");
    }
    else{
        [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(lockToLocation:) userInfo:nil repeats:NO];
        NSLog(@"Waiting Started");
    }
    NSLog(@"Waiting Finished");
    [ViewController updateArray];
    [self updateNodes];
    
}
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation{
    NSLog(@"Map View Method Called");
    MKPinAnnotationView *pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];
    pinView.pinColor = [currentParty getPartyColor];
    currentParty.annot.title = [currentParty getPartyName];
    return pinView;
}
-(void) updateNodes{
    for(Party *party in allParties){
        if(!party.alreadyAdded){
            party.alreadyAdded = YES;
            currentParty = party;
            [map addAnnotation:currentParty.annot];
            NSLog(@"Adding Successful!");
        }
    }
}

Really not liking the way I have to deal with custom annotations!
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top