mapkit-ios-demo icon indicating copy to clipboard operation
mapkit-ios-demo copied to clipboard

Could not cast value of type 'YMKPlacemarkMapObject' (0x11686f1d8) to 'YMKPlacemarkMapObject' (0x11d783958).

Open max270598 opened this issue 2 years ago • 1 comments

i have cluster collection and for placeMarks in this collection i added YMKMapObjectTapListener.

Screenshot 2022-07-14 at 10 54 01

this is my onMapObjectTap method

Screenshot 2022-07-14 at 10 56 36

and when i click on a placemark, i got crash with this error "Could not cast value of type 'YMKPlacemarkMapObject' (0x111c031d8) to 'YMKPlacemarkMapObject' (0x118b17960)."

Screenshot 2022-07-14 at 10 58 56

What am i doing wrong?

max270598 avatar Jul 14 '22 08:07 max270598

try this guard let placemarkObj = mapObject as? YMKPlacemarkMapObject else { return false } return true

Aharonik1 avatar Oct 20 '22 05:10 Aharonik1

Because you are using clusterized collection you should implement two tap listeners: one for object taps (the one you have implemented), and the other one for cluster taps, e.g.:

    func onClusterTap(with cluster: YMKCluster) -> Bool {
        // do smth with cluster here (zoom in for example)
        return true
    }

    func onMapObjectTap(with mapObject: YMKMapObject, point _: YMKPoint) -> Bool {
        guard let placemarkObj = mapObject as? YMKPlacemarkMapObject else { return false } 
        // do smth with object here 
        return true
    }

xzeror avatar Nov 12 '22 20:11 xzeror