ViewController,tableView和Mapkit

时间:2017-05-23 10:01:19

标签: ios swift xcode mapkit

由于一个不寻常的问题,我在项目进展中陷入困境,我在ViewController中添加了一个mapKit和一个tableView ..我正在寻找的结果就像这样enter image description here

因此当用户进入此页面时,会根据tableView的参数自动在地图上启动导航课程。我写了这段代码来实现这个目标

    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

好像自动打开地图应用程序;我不想要这个,我希望我的地图像一个viewController的子视图,我也试图添加一些约束,但它不起作用,因为当然它不是我的地图变大,而是视图上面打开的地图应用程序。我想知道如何调整它。

1 个答案:

答案 0 :(得分:0)

这是不可能的。你必须自己编写代码。例如,您可以使用MKDirections执行此操作,或者使用框架。

您可以谷歌“快速转弯导航”或使用

带地图套件的

Apple Providing Directions

相关问题