我是新來的Xcode所以請原諒我的問題,如果它是愚蠢的傳遞信息鏈接到註釋
我有一個鏈接到一個UIAlertView中框的註釋其中有兩個選擇(接近,方向在這裏) 第二個按鈕應打開蘋果地圖應用程序,並立即向用戶提供轉向導航。
現在我的問題是,我在我的地圖上有很多註釋,當按下每個註釋時,用戶必須獲得導航選項。所以我沒有固定的MKPlacemark,我需要將按下的註釋中的信息傳遞給MKPlacemark,以便MKMapItem獲得所需的標題位置。
我的代碼是:
我的註釋方法,它會顯示一個UIAlertView中:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{
// get reference to the annotation to access its data
VBAnnotation *ann = (VBAnnotation *)view.annotation;
// deselect the button
[self.mapView deselectAnnotation:ann animated:YES];
// display alert view to the information
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:ann.title message:ann.info delegate:self cancelButtonTitle:@"close" otherButtonTitles:@"direction to here", nil];
[alert show];
}
這裏我UIAlertView中按鈕動作:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:@"direction to here"])
{
//now here i tried a fixed coordination, but i need to pass the actual coordination pressed by the UIAlertView
CLLocationCoordinate2D coordinate;
coordinate.latitude = 24.41351;
coordinate.longitude = 39.543002;
MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil];
MKMapItem *navigation = [[MKMapItem alloc]initWithPlacemark:placemark];
NSDictionary *options = @{MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeWalking};
[navigation openInMapsWithLaunchOptions:options];
}
}
這裏是我的標籤列表
的樣本NSMutableArray *annotations = [[NSMutableArray alloc] init];
CLLocationCoordinate2D location;
VBAnnotation *ann;
//Annotations List
// Mecca Pin
location.latitude = MEC_LATITUDE;
location.longitude = MEC_LONGITUDE;
ann = [[VBAnnotation alloc] init];
[ann setCoordinate:location];
ann.title = @"NewHorizons Institute";
ann.subtitle = @"English and computer training center";
[annotations addObject:ann];
[self.mapView addAnnotations:annotations];
當然,我有一個名爲VBAnnotation
感謝類...
謝謝...我VBAnnotation對象包含5個屬性: //座標 //標題 //字幕 //信息 //名 但我需要傳遞的唯一事情是協調...... 謝謝...這篇文章真的很有幫助 –
@AliRaslan如果這個答案有助於解決你的問題,那麼如果你接受了它,那將會很好。否則,您可以編寫自己的答案並接受該答案。 – herzbube
對不起:$我是新來的網站,並不知道接受按鈕:) –