我正在尝试实现某些功能:
我想要一个UITextView,它恰好是某个地方的地址,当点击此UITextView时,将用户带到Apple Maps并在UITextView中显示该地址的位置。关于如何做到的任何想法?
到目前为止我一直在尝试做的事情:
import MapKit
@IBOutlet weak var firstAddressTapped: UITextView!
func viewDidLoad() {
let attributedString = NSMutableAttributedString(string: "The address of my place")
attributedString.addAttribute(.link, value: "http://maps.apple.com/?daddr=The+address+of+my+place", range: NSRange(location: 19, length: 55))
firstAddressTapped.attributedText = attributedString
}
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
UIApplication.shared.open(URL)
return false
}
谢谢!
您可以这样传递地址;
UIApplication.sharedApplication().openURL(NSURL(string: "http://maps.apple.com/?address=The+address+of+my+place")!)