Можно использовать такой вариант - получить координаты объекта и по ним уже определить подробные данные, используя метод, который я уже приводил в другом своем ответе
class LocationAtTapViewController: UIViewController {
@IBOutlet weak var mapView: YMKMapView!
let searchManager = YMKSearch.sharedInstance().createSearchManager(with: .combined)
var searchSession: YMKSearchSession?
let TARGET_LOCATION = YMKPoint(latitude: 59.945933, longitude: 30.320045)
override func viewDidLoad() {
super.viewDidLoad()
mapView.mapWindow.map.move(
with: YMKCameraPosition(target: TARGET_LOCATION, zoom: 15, azimuth: 0, tilt: 0),
animationType: YMKAnimation(type: YMKAnimationType.smooth, duration: 0.2),
cameraCallback: nil)
mapView.mapWindow.map.addTapListener(with: self)
}
}
extension LocationAtTapViewController: YMKLayersGeoObjectTapListener {
func onObjectTap(with event: YMKGeoObjectTapEvent) -> Bool {
let obj = event.geoObject
print("name:", obj.name ?? "unknown")
guard let point = obj.geometry.first?.point else {
return true
}
print("coordinates: lat \(point.latitude) lon \(point.longitude)")
let responseHandler = {(searchResponse: YMKSearchResponse?, error: Error?) -> Void in
if let response = searchResponse {
self.onSearchResponse(response)
}
}
searchSession = searchManager.submit(with: point, zoom: 15, searchOptions: YMKSearchOptions(), responseHandler: responseHandler)
return true
}
func onSearchResponse(_ response: YMKSearchResponse) {
for searchResult in response.collection.children {
guard let obj = searchResult.obj else {
continue
}
guard let objMetadata = obj.metadataContainer.getItemOf(YMKSearchToponymObjectMetadata.self) as? YMKSearchToponymObjectMetadata else {
continue
}
let address = objMetadata.address
let formattedAddress = address.formattedAddress
let postalCode = address.postalCode ?? "none"
let additionalInfo = address.additionalInfo ?? "none"
print("formattedAddress", formattedAddress)
print("postalCode", postalCode)
print("additionalInfo", additionalInfo)
print("components:")
address.components.forEach {
let value = $0.name
$0.kinds.forEach {
let kind = YMKSearchComponentKind(rawValue: UInt(truncating: $0))
switch kind {
case .country:
print("country: \(value)")
case .region:
print("region: \(value)")
case .locality:
print("locality: \(value)")
case .street:
print("street: \(value)")
case .house:
print("house number: \(value)")
default:
break
}
}
}
print("==========")
}
}
}