【发布时间】:2023-04-04 03:39:01
【问题描述】:
所以我有这个按钮可以使用谷歌地图指示方向,问题是我不知道如何在 UIButton 中编写正确的目标选择器,因为最新的 swift
这是我的按钮:
directionButton.addTarget(self, action: #selector(ViewController.goToMap(String(format: "%.6f", place.coordinate.latitude), longitude: String(format: "%.6f", place.coordinate.longitude))), forControlEvents: UIControlEvents.TouchUpInside)
这是我的功能:
func goToMap(latitude: String, longitude: String) {
print("function gotoMap works!!!!")
if (UIApplication.sharedApplication().canOpenURL(NSURL(string:"comgooglemaps://")!)) {
UIApplication.sharedApplication().openURL(NSURL(string:
"comgooglemaps://?saddr=&daddr=\(latitude),\(longitude)&directionsmode=driving")!)
} else {
print("Can't use comgooglemaps://")
var addressToLinkTo = ""
addressToLinkTo = "http://?saddr=&daddr=\(latitude),\(longitude)&directionsmode=driving"
addressToLinkTo = addressToLinkTo.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!
let url = NSURL(string: addressToLinkTo)
UIApplication.sharedApplication().openURL(url!)
}
}
谁能帮帮我?
【问题讨论】:
标签: ios google-maps uibutton swift2 xcode7