0
所以我有這個按鈕使用谷歌地圖給方向,問題是我不知道,因爲最新的迅速如何在swift iOS中編寫適當的目標選擇器?
這裏如何在UIButton的寫適當的目標選擇是我的按鈕:
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!)
}
}
任何人都可以幫助我嗎?