Accessing MKLocalSearchResponse item (swift)

丶灬走出姿态 提交于 2019-11-29 17:50:17

The answer is:

var newRecordAddress = (localSearchResponse.mapItems[0] as! MKMapItem).placemark

This object contains all information you need. Checked it in demo project

Address only:

var newRecordAddress = (localSearchResponse.mapItems[0] as! MKMapItem).placemark
let addressOnly = newRecordAddress.name + ", " + newRecordAddress.title

newRecordAddress.name is place's name newRecordAddress.title is place's address you required

Because mapItems is an array, you need to call first to access the first element of that array. This will return an MKMapItem, so you can get the placemark property with this code:

localSearchResponse.mapItems.first.placemark
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!