gpt4 book ai didi

ios - Yandex MapKit iOS : cluster and placemarks

转载 作者:行者123 更新时间:2023-12-01 19:37:27 29 4
gpt4 key购买 nike

我正在使用 Yandex Mapkit iOS SDK 对于我的一个项目。
似乎 SDK 允许添加地标是一个集群。但是我不能像添加一个地标作为 mapObject 一样使用 userData 添加自定义地标。 .我想检测标记上的点击 Action 。

// 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)
在集群中添加标记,可以仅使用 YMKPoint 将标记添加到集群中.我找不到添加 placemark 的方法集群内的对象
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)

最佳答案

定义一个带有监听器的集合。用任意点填充数组。遍历数组并将每个点添加到集合中。向集合添加点时,返回 YMKPlacemarkMapObject,添加用户数据。并扩展您的 Controller 委托(delegate)方法。

并用 Yandex 查看测试项目 - https://github.com/yandex/mapkit-ios-demo/blob/master/MapKitDemo/ClusteringViewController.swift

class MapViewController: UIViewController {
@IBOutlet weak var mapView: YMKMapView!
var collection: YMKClusterizedPlacemarkCollection?
var point: [YMKPoint] = [] // Fill the array with any points

override func viewDidLoad() {
super.viewDidLoad()

collection = mapView.mapWindow.map.mapObjects.addClusterizedPlacemarkCollection(with: self)
collection?.addTapListener(with: self)

for point in points {
let placemark = collection?.addPlacemark(with: point,
image: UIImage(named: "some_image")!,
style: YMKIconStyle.init())
placemark?.userData = "user data"
}

collection.clusterPlacemarks(withClusterRadius: 60, minZoom: 15)
}
}

extension MapViewController: YMKMapObjectTapListener {
func onMapObjectTap(with mapObject: YMKMapObject, point: YMKPoint) -> Bool {
guard let userPoint = mapObject as? YMKPlacemarkMapObject else {
return true
}

print(userPoint.userData)
}
}

关于ios - Yandex MapKit iOS : cluster and placemarks,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59614848/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com