I have the following Objective-C code:
NSString *urlStr=[[NSString alloc] initWithFormat:@"http://www.prestocab.com/driver/ajax/getFriendsOnMap.php"];
NSURL *url=[NSURL URLWithString:urlStr];
__block ASIFormDataRequest *request=[[ASIFormDataRequest alloc ]initWithURL:url];
[request setDelegate:self];
[request setPostValue:[NSString stringWithFormat:@"%f",swCoord.latitude ] forKey:@"sw_lat"];
[request setPostValue:[NSString stringWithFormat:@"%f",swCoord.longitude ] forKey:@"sw_lng"];
[request setPostValue:[NSString stringWithFormat:@"%f",neCoord.latitude ] forKey:@"ne_lat"];
[request setPostValue:[NSString stringWithFormat:@"%f",neCoord.longitude ] forKey:@"ne_lng"];
[request setCompletionBlock:^{
NSLog(@"%@",[request responseString]);
SBJsonParser *parser=[[SBJsonParser alloc]init];
//NSDictionary *obj=[parser objectWithString:[request responseString] error:nil];
NSDictionary *arr=[parser objectWithString:[request responseString] error:nil];
MapViewAnnotation *annotation=[[MapViewAnnotation alloc]init];
for(int i=0;i<arr.count;i++){
NSDictionary *obj=[arr objectForKey:[NSString stringWithFormat:@"%d",i]];
CLLocationCoordinate2D coord;
coord.latitude=[[obj objectForKey:@"lat"] doubleValue];
coord.longitude=[[obj objectForKey:@"lng"] doubleValue];
[annotation initWithTitle:[obj objectForKey:@"uname"] andCoordinate:coord];
//[self.mapView performSelectorOnMainThread:@selector(addAnnotation) withObject:annotation waitUntilDone:YES];
[self.mapView addAnnotation:annotation];
}
[annotation release];
//[self.mapView addAnnotations:annotations];
//[annotations release];
}];
[request setFailedBlock:^{
}];
[request startAsynchronous];
As you can see, I'm getting some data from my website using ASIHttpRequest, parsing the result and hoping to put annotations on the MKMapView.
Trouble is, when I call [self.mapView addAnnotation:...] I keep getting one of these EXC_BAD_ACCESS errors that I simply cannot get to the bottom of.
Anyone have any suggestions?
Many thanks in advance,