私の問題は、デリゲートとの接続を接続しましたが、デリゲートメソッドを中断していないことです。注釈のアドレスを取得し、注釈ビューに表示したいと考えています。住所の取得に成功しましたが、マップビューの読み込みに時間がかかるため、 NsConnection メソッドを使用しました。私が間違いを犯した場合は、私を助けてください。
CLLocationCoordinate2D coordinate;
coordinate.latitude = 28.6667;
coordinate.longitude = 77.2167;
clusterMap.region = MKCoordinateRegionMakeWithDistance(coordinate, 5000, 5000);
self.blocks = 4;
self.minimumClusterLevel = 100000;
// super.delegate = self;
zoomLevel = clusterMap.visibleMapRect.size.width * clusterMap.visibleMapRect.size.height;
NSMutableArray *pins = [[NSMutableArray alloc]init];
for(int i =0 ; i < 50; i++)
{
CGFloat latDelta = rand()*0.125/RAND_MAX - 0.02;
CGFloat lonDelta = rand()*0.130/RAND_MAX - 0.08;
newCoord.latitude = coordinate.latitude+latDelta;
newCoord.longitude = coordinate.longitude+lonDelta;
NSString *urlString = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&sensor=false",newCoord.latitude, newCoord.longitude];
// NSLog(@"Is%@ main thread", ([NSThread isMainThread] ? @"" : @" NOT"));
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:request delegate:self];
[connection start];
customannView = [[AnnotationView alloc]initWithLatitude:newCoord.latitude andLongitude:newCoord.longitude];
// customannView.title = [NSString stringWithFormat:@"Pin %i",i];
customannView.title =locationString;
customannView.subtitle = [NSString stringWithFormat:@"Pin %i",i];
customannView.coordinate = newCoord;
customannView.imgName = @"bookmark1.png";
[pins addObject:customannView];
[connection cancel];
}
[self addAnnotations:pins];
UILongPressGestureRecognizer *dropPin = [[UILongPressGestureRecognizer alloc] init];
[dropPin addTarget:self action:@selector(handleLongPress:)];
dropPin.minimumPressDuration = 0.5;
[clusterMap addGestureRecognizer:dropPin];
}
// [self performSelector:@selector(mapViewWillStartLoadingMap:) withObject:nil afterDelay:0.01];
UILongPressGestureRecognizer *dropPin = [[UILongPressGestureRecognizer alloc] init];
[dropPin addTarget:self action:@selector(handleLongPress:)];
dropPin.minimumPressDuration = 0.5;
[clusterMap addGestureRecognizer:dropPin];
}
#pragma mark NSURLConnection Delegate Methods
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
// A response has been received, this is where we initialize the instance var you created
// so that we can append data to it in the didReceiveData method
// Furthermore, this method is called each time there is a redirect so reinitializing it
// also serves to clear it
[responseData setLength:0];
NSLog(@"Response :: %@",responseData);
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
// Append the new data to the instance variable you declared
[responseData appendData:data];
}
- (NSCachedURLResponse *)connection:(NSURLConnection *)connection
willCacheResponse:(NSCachedURLResponse*)cachedResponse {
// Return nil to indicate not necessary to store a cached response for this connection
return nil;
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
// The request is complete and data has been received
// You can parse the stuff in your instance variable now
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
// The request has failed for some reason!
// Check the error var
}