Reputation: 161
I'm looping through SQLite results and add annotations to a map
while(sqlite3_step(statement) == SQLITE_ROW) {
double latitude = sqlite3_column_double(statement, 0);
double longitude = sqlite3_column_double(statement, 1);
MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
CLLocationCoordinate2D location;
location.latitude = latitude;
location.longitude = longitude;
[point setCoordinate:(location)];
[point setTitle:venuename];
[point setSubtitle:@"hello"];
[mapView addAnnotation:point];
[point release];
}
Works great. Now, lets say I want to Select the 3nd Annotation, I do
id<MKAnnotation> myAnnotation = [mapView.annotations objectAtIndex:2];
[mapView selectAnnotation:myAnnotation animated:NO];
However, it seems annotations are added to the map in random order, and not according to the order of my loop. So the "objectAtIndex:2" is always a different annotation, and not the second Database result.
Is there a way how I can give an annotation some unique ID before I add them to the map, which I can then use to select them ?
Upvotes: 1
Views: 2064