因为一个不寻常的问题,我卡在了我的项目进度中,我在 ViewController 中添加了一个 mapKit 和一个 tableView..我正在寻找的结果是这样的 enter image description here
所以当用户进入这个页面时,根据tableView的参数,自动在 map 上开始一个导航过程。我写了这段代码来实现这一点
override func viewDidLoad() {
super.viewDidLoad()
map.showsUserLocation = true
map.delegate = self
let latitude:CLLocationDegrees = 41.869909
let longitude:CLLocationDegrees = 12.512516
let regionDistance:CLLocationDistance = 1000;
let coordinates = CLLocationCoordinate2DMake(latitude, longitude)
let regionSpan = MKCoordinateRegionMakeWithDistance(coordinates, regionDistance, regionDistance)
let options = [MKLaunchOptionsMapCenterKey: NSValue(mkCoordinate: regionSpan.center), MKLaunchOptionsMapSpanKey: NSValue(mkCoordinateSpan: regionSpan.span)]
let placemark = MKPlacemark(coordinate: coordinates)
let mapItem = MKMapItem(placemark: placemark)
mapItem.name = "My Position"
mapItem.openInMaps(launchOptions: options)
}
但问题是,用户在上面的viewController中输入的结果是这个enter image description here
好像自动打开 map 应用;我不想要这个,我希望我的 map 像 viewController 的 subview ,我也尝试添加一些约束但它没有用,因为当然不是我的 map 变大而是上面打开的 map 应用程序的 View .我想知道我该如何调整它。
最佳答案
这是不可能的。你必须自己编写代码。例如,您可以使用 MKDirections 或为此使用框架来执行此操作。
您可以在谷歌上搜索“快速转弯导航”或使用
Apple Providing Directions与 map 套件
关于ios - ViewController、tableView 和 Mapkit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44131649/