如何使用 Mapkit ios swift 选择地图上已存在的地点

问题描述 投票:0回答:1

我想让我的应用程序在点击地图上已存在的位置时打开另一个视图控制器。当您打开地图时,地图上会显示许多地点及其名称,我认为它们被称为地标。我想做到这一点,以便当用户选择这样的地标时,我向他显示有关它的信息。问题是我希望用户直接点击这样的地方并且不想在地图上进行注释这可能吗?

ios swift mapkit mkmapview
1个回答
0
投票

您可以使用 selectableMapFeatures 显示 iOS 16 中的那些。 在你的 viewDidLoad 中它看起来像这样:

mapView.selectableMapFeatures = [.pointsOfInterest]

然后要使用 Apple 的默认标注,您需要在符合 MKMapViewDelegate 的情况下使用它:

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
    return nil
}

但是您可以对其进行自定义,从注释中获取更多信息等。这是有关 Apple WWDC 的链接。 https://developer.apple.com/videos/play/wwdc2022/10035/

你想要的部分在20分钟左右。

© www.soinside.com 2019 - 2024. All rights reserved.