我是 Xcode 的新手,所以如果我的问题很愚蠢,请原谅我的问题
我有一个链接到 UIAlertView 框的注释,它有两个选择(关闭,到这里的方向)第二个按钮应该打开苹果地图应用程序并立即为用户提供轮流导航。
现在我的问题是我的地图上有很多注释,当按下每个注释时,用户必须获得导航选项。所以我没有固定的 MKPlacemark,我需要将信息从按下的注释传递给 MKPlacemark,以便 MKMapItem 获得所需的航向位置。
我的代码是:
我的 Annotation 方法将显示 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 的课程
谢谢 ...