- (void)mapView:(MAMapView *)mapView didSelectAnnotationView:(MAAnnotationView *)view {
NSLog(@"选中了标注%f, %f",view.annotation.coordinate.latitude, view.annotation.coordinate.longitude);
WeakSelf;
UIAlertController *alerController = [UIAlertController alertControllerWithTitle:@"导航" message:@"选择导航方式" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *action = [UIAlertAction actionWithTitle:@"高德地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}];
UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"百度地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}];
UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
// [view setSelected:NO animated:YES]; //有BUG
// view.selected = NO; //有BUG
// 取消选中正确方式
StrongSelf;
for (id <MAAnnotation>annotation in strongSelf.mapView.annotations) {
[strongSelf.mapView deselectAnnotation:annotation animated:YES];
}
}];
[alerController addAction:action];
[alerController addAction:action1];
[alerController addAction:action2];
[self.navigationController presentViewController:alerController animated:YES completion:nil];
}
本文介绍了一个iOS应用中实现地图导航选择功能的方法。当用户在地图上点击一个位置时,会弹出一个警告框,提供使用高德地图或百度地图进行导航的选项,同时提供了取消按钮。文章展示了如何通过Swift代码实现这一功能,包括使用UIAlertController创建警告框,以及如何在不同的地图应用间切换。
552

被折叠的 条评论
为什么被折叠?



