gpt4 book ai didi

swift - Uibutton传递位置信息并开始快速在 map 上导航

转载 作者:搜寻专家 更新时间:2023-11-01 05:50:21 25 4
gpt4 key购买 nike

我有 CLLocationcooridinate2d 和位置详细信息的数组内容。我把它放在带有 Uibutton 的 tableview 单元格上,我所做的是试图通过 Uibuttom 传递特定的单元格信息并启动 map View 的新 View 并开始导航。这是我的代码:

   var tripspot:[tripSpot] = [
tripSpot( title: "一中商圈", coordinate: CLLocationCoordinate2DMake(24.149062, 120.684891), regionRadius: 300.0, location: "台中市北區一中街", type: "Food",cllocation:CLLocation(latitude: 24.181143, longitude: 120.593158))


func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("MapCell") as! mapTableViewCell
if searchController.active{
cell.title.text = searchResults[indexPath.row].title
cell.location.text = searchResults[indexPath.row].location
cell.naviButton.tag = indexPath.row
cell.naviButton.addTarget(self, action: Selector("tapDidNavi"), forControlEvents: .TouchUpInside)

return cell
}else{
cell.title.text = tripspot[indexPath.row].title
cell.location.text = tripspot[indexPath.row].location
cell.naviButton.tag = indexPath.row
cell.naviButton.addTarget(self, action: Selector("tapDidNavi"), forControlEvents: .TouchUpInside)
print(cell.naviButton.tag.description)
return cell
}


}

@IBAction func tapDidNavi(sender: UIButton){



}

谢谢你的建议!

最佳答案

您可以使用 MKMapItem.openMapsWithItems:launchOptions:在 map 应用中开始精细导航。

来自文档:

If you specify the MKLaunchOptionsDirectionsModeKey option in the launchOptions dictionary, the mapItems array must have no more than two items in it. If the array contains one item, the Maps app generates directions from the user’s current location to the location specified by the map item. If the array contains two items, the Maps app generates directions from the location of the first item to the location of the second item in the array.

@IBAction func tapDidNavi(sender: UIButton){

let location = self.tripspot[sender.tag]

let placemark = MKPlacemark(
coordinate: coordinate,
addressDictionary: nil
)

let mapItem = MKMapItem(placemark: placemark)
mapItem.name = location.title

let options = [
MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving
]

MKMapItem.openMapsWithItems([mapItem], launchOptions: options)
}

关于swift - Uibutton传递位置信息并开始快速在 map 上导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38345371/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com