Detect address from UITextView and show it map on tap
There is an opt开发者_高级运维ion in UITextView properties to detect address from the the text view text. However I am not able to do that. The text view is not in editable mode.
Do you know how to detect address from text view? Is there a format that the address must have to be detected from the text view?
A UITextView won't automatically detect if text entered in the control is an address or provide you with the data you need to map the address on a map. It is simple a control to display arbitrary text data to the user:
You typically use a text view to display multiple lines of text, such as when displaying the body of a large text document.
I am not familiar with any algorithms to detect an address from a block of text, but if you work that part out, you can use geocoding to translate from the address to the latitude/longitude value you need to display it on a map.
I realize this answer is 3 years too late, but I was recently struggling with a similar problem (data detector for phone on mapview). I had datadetectors turned on, and had editable turned off -- but I found that if I added a "\n" to the end of the string, the detector suddenly started working.
For future folks landing here from search results, check out NSDataDetector
let detector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType.address.rawValue)
if detector?.firstMatch(in: textView.text, options: [], range: NSRange(textView.text) != nil,
let addressRange = Range(match.range, in: textView.text) {
let address = textView.text[range]
// do something with address
}
I'm not using it in the context of an editable text view, but you could easily try to detect address (or other data type) each time the text view is edited
精彩评论