I am using Yandex Mapkit iOS SDK for one of my projects.
It seems that SDK allows adding placemarks is a cluster. Bu I can not add a custom place mark with userData as the same way adding a placemark as a mapObject
. I want to detect tap action on a marker.
// adding markers as mapobjects:
let point = YMKPoint(coordinate: CLLocationCoordinate2D(latitude: Double(hit.geom!.lat ?? 0), longitude: Double(hit.geom?.lon ?? 0)))
let placemark: YMKPlacemarkMapObject
self.mapObjects = self.mapView.mapWindow.map.mapObjects
placemark = mapObjects!.addPlacemark(with: point, image: #imageLiteral(resourceName: "marker"))
placemark.userData = MarkerUserData(id: Int(hit.id!)!, description: hit.plate!)
placemark.isDraggable = false
placemark.addTapListener(with: self)
mapObjects!.addListener(with: self)
Adding markers in a cluster, markers can be added to a cluster using only YMKPoint
. I could not find a way to add a placemark
object inside a cluster
let point = YMKPoint(coordinate: CLLocationCoordinate2D(latitude: Double(hit.geom!.lat ?? 0), longitude: Double(hit.geom?.lon ?? 0)))
let placemark: YMKPlacemarkMapObject
collection.addPlacemark(with: point, image: #imageLiteral(resourceName: "marker"))
// Placemarks won't be displayed until this method is called. It must be also called
// to force clusters update after collection change
collection.clusterPlacemarks(withClusterRadius: 20, minZoom: 5)
Define a collection with a listener. Fill the array with any points. Go through the array and add each point to the collection. When adding a point to the collection, YMKPlacemarkMapObject is returned, adding user data. And extend your controller delegate method.
And look at the test project with Yandex - https://github.com/yandex/mapkit-ios-demo/blob/master/MapKitDemo/ClusteringViewController.swift