2011-01-25 4 views
1

물리적 인 지점을 나타내는 일련의 객체에 대해 long/lat를 기반으로 영역의 핀을 떨어 뜨리는 mapView 및 Annotation 뷰가 있습니다. 공유 응용 프로그램지도를 열어 해당 위치에서 길 찾기를 제공하는 주석을 가져 왔습니다. 그러나 지점 개체/주석에서 주소를 가져 오는 방법을 알 수 없을 때이를 전달합니다. CalloutAccessoryControlTapped 화재 :mapView.SelectedAnnotations에서 객체 속성 가져 오기

지점 개체 : 콜 아웃이 명중 할 때


CLLocationCoordinate2D newCord; 
newCord.latitude = 34.0038; 
newCord.longitude = -84.0965; 
corp = [[LocationwithAnnotation alloc] initWithCoordinate:newCord]; 
corp.mTitle = @"Corp Office"; 
corp.mSubTitle = @"123 Main Street, Duluth GA"; 
[mapView addAnnotation:corp]; 
[corp release]; 

newCord.latitude = 33.0038; 
newCord.longitude = -84.3965; 
uga = [[LocationwithAnnotation alloc] initWithCoordinate:newCord]; 
uga.mTitle = @"uga Office"; 
uga.mSubTitle = @"123 Main Street, Atlanta GA"; 
[mapView addAnnotation:uga]; 
[corp release]; 

이 주석을지도에 추가 된 후, 나는지도에 밀어 TP 할 수 있도록하려면 app에 선택한 주석 (예 : corp) 자막을 추가합니다.

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{ 
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"]; 
annView.pinColor = MKPinAnnotationColorGreen; 
annView.animatesDrop=TRUE; 
annView.canShowCallout = YES; 
annView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
annView.calloutOffset = CGPointMake(-5, 5); 
return annView; 
} 

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control { 
NSLog(@"%@", mapView.selectedAnnotations); 
UIAlertView *alert = [[UIAlertView alloc] 
initWithTitle:@"Directions" 
message:@"Get directions to this branch?" 
delegate:self 
cancelButtonTitle:@"No" 
otherButtonTitles: @"Yes, please", nil]; 
[alert show]; 
[alert release]; 

} 

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { 
if (buttonIndex == 1) { 
MKUserLocation *loc = mapView.userLocation.location; 
double latitude = loc.location.coordinate.latitude; 
NSString *lat = [NSString stringWithFormat:@"%f",latitude]; 
double longitude = loc.location.coordinate.longitude; 
NSString *lon = [NSString stringWithFormat:@"%f",longitude]; 
NSString *base = @"http://maps.google.com/maps?"; 
NSString *dest = [@"daddr=" stringByAppendingString: mapView.SelectedAnnotations; // Doesn't work. 

내 NSLog 덤핑되는 유일한 것은 내가 그에서 개체를 잡을 수 있도록하는 방법 있습니다 .. SelectedAnnotation 단지 메모리 주소입니다?

답변

0

당신이 여기에 AlertView를 사용하는 대신 직접 calloutAccessoryControlTapped을 활용하여 주장하는 경우, 난 그냥 alertView의 meessage 선택한 주석의 자막을 추가 한 다음 clickedButtonAtIndex 방법에 그것을 구문 분석

2
for(YourMKAnnotationProtocolClass *object in _mapView.selectedAnnotation){ 

     NSLog("%@", object.title); // or you can access other information you've defined 
}