E
E
Emma2019-08-06 17:45:05
iOS
Emma, 2019-08-06 17:45:05

YndexMapKit. How to get object data to display in infobox?

Good afternoon.
It is necessary to display the object data in a small infobox at the bottom.
Here's what I'm doing now:
1. Subscribed to the YMKMapObjectTapListener listener
2. Added the listener to my mapObjects

override func viewDidLoad() {
        super.viewDidLoad()
        let mapObjects = mapView.mapWindow.map.mapObjects
        mapObjects.addTapListener(with: self)
}

3. In the delegate method, I'm trying to get mapObject data, which is of type Any? and always nil
class AddressesViewController: UIViewController, YMKMapObjectTapListener {
    
    func onMapObjectTap(with mapObject: YMKMapObject, point: YMKPoint) -> Bool {
        guard let placemark = mapObject as? YMKPlacemarkMapObject else { return false }
        let data = placemark.userData
        print(data)
        return true
    }

Problems:
a) How to get object data correctly?
b) Delegate method
onMapObjectTap(with mapObject: YMKMapObject, point: YMKPoint)
is not always called, you have to click several times to get there, meanwhile the logs constantly show messages like "No 'name' attribute in object 1923987 in layer mapj".
I don't have any other listeners added, so what's the problem?
I will be very glad to help!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question