在uivew中显示引脚信息

时间:2017-04-28 17:47:27

标签: ios swift uiview mapkit

我正在使用应用程序,这个应用程序使用mapkit,现在我能够显示用户当前位置,当我点击一个pin我能够显示信息但我想要做的是显示地图视图中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

1 个答案:

答案 0 :(得分:1)

很抱歉,我无法发表评论,因为我们尚未提供相关要求,但我相信以下功能可以为您提供帮助:

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
}