ios - 在 uiview 中显示引脚信息

标签 ios swift uiview mapkit

我正在使用一个应用程序,这个应用程序使用 mapkit,现在我可以显示用户当前位置,当我点击一个图钉时我可以显示信息,但我想做的是显示 map View 上 uiview 中的图钉信息,因此当我点击图钉时,信息应该出现在 uiview 的标签中,而不是出现在图钉上。这是我的代码和屏幕截图。

希望你能帮助我

    let locations = hardCodedLocationData()

        var annotations = [MKPointAnnotation]()

        for dictionary in locations {

            let lat = CLLocationDegrees(dictionary["latitude"] as! Double)
            let lon = CLLocationDegrees(dictionary["longitude"]as! Double)

            let coordinate = CLLocationCoordinate2D(latitude: lat, longitude: lon)
            let name = dictionary["nombre"] as! String
            let adress = dictionary["direccion"] as! String

            let annotation = MKPointAnnotation()
            annotation.coordinate = coordinate
            annotation.title = "\(name)"
            annotation.subtitle = "\(adress)"
            annotations.append(annotation)
        }

        self.mapView.addAnnotations(annotations)
    }

  func hardCodedLocationData() -> [[String : AnyObject]] {
    return[
          ["nombre" : "xxxxxxx" as AnyObject,
                "direccion" : "xxxxxxxx" as AnyObject,
                "latitude" : 19.43017222686738 as AnyObject,
                "longitude" : -99.20263767242432  as AnyObject],
            ["nombre" : "xxxxxxxxxx " as AnyObject,
                "direccion" : "xxxxxxxxxxx" as AnyObject,
                "latitude" : 19.434057416826118 as AnyObject,
                "longitude" : -99.19233798980713  as AnyObject],

            [ "nombre" : "xxxxxxxxxxx" as AnyObject,
                "direccion" : "xxxxxxxxxx" as AnyObject,
                "latitude" : 19.43017222686738 as AnyObject,
                "longitude" : -99.19692993164062  as AnyObject]
            ]


    }

This is the mapView

最佳答案

抱歉,我无法发表评论,因为还没有所需的相关要点,但我相信以下功能应该对您有所帮助:

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
    if view is MKPinAnnotationView {
        yourLabel.text = //call up text
    }
}

//or change if view is to
if let views = view as? MKPinAnnotationView {
   //do your updating of labels
}

关于ios - 在 uiview 中显示引脚信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43686097/

相关文章:

ios - Swift 框架可以引用另一个 Swift 框架的类扩展吗?

ios - 应用更新发布时plist文件会被覆盖吗

ios - 无法在 iPhone 上运行应用程序

Swift,如何在按下按钮时播放声音

ios - 不使用代码将 xib UIView 添加到 Storyboard View Controller

ios - UIView 图层上的阴影

ios - Paypal Kinvey 集成

swift - 快速从 findObjectsInBackgroundWithBlock 获取数据

swift - UICollectionView 单元格间距相等

ios - 如何在 iOS 5 中创建可以向任何方向滚动的 View ,如 map ?