按钮单击事件在地图标记信息窗口内

时间:2016-08-03 07:56:06

标签: swift google-maps

我想为Google地图标记创建一个信息窗口,以便在我的iOS应用程序的信息窗口中提供按钮点击事件。有没有办法做到这一点?

1 个答案:

答案 0 :(得分:0)

希望这可以帮到你

extension ViewController: MKMapViewDelegate {
    func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
        if annotation is MKUserLocation {
            return nil
        }
        let identifier = "MyCustomAnnotation"

        var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier)
        if annotationView == nil {
            annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
            annotationView?.canShowCallout = true
        } else {
            annotationView!.annotation = annotation
        }

        let myButton = UIButton()

        annotationView?.leftCalloutAccessoryView = myButton

        return annotationView
    }

}