0

我正在尝试制作一个您单击的图钉,然后会出现标题和副标题。

到目前为止,这是我的代码:

    let span : MKCoordinateSpan = MKCoordinateSpanMake(0.1, 0.1)
    let location : CLLocationCoordinate2D = CLLocationCoordinate2DMake(40.750517, -73.987271)
    let region : MKCoordinateRegion = MKCoordinateRegionMake(location, span)
    mapView.setRegion(region, animated: true)

    let annotation = MKPointAnnotation()

    annotation.coordinate = location
    annotation.title = "Bus Stop"
    annotation.subtitle = "Street Name at Street Name"
    mapView.addAnnotation(annotation)

问题是我的出现了一个圆形气泡,这不是我想要的,我想要那些在应用程序中使用的传统红色别针,当你点击更多信息时会显示。

4

2 回答 2

0

您必须实现委托方法来更改注释的视图。

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
  //Implement Your custom view for annoation
}
于 2018-07-26T11:07:22.670 回答
0

扩展 YourViewC: MKMapViewDelegate {

    func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
        if annotation is MKUserLocation
        {
            return nil
        }
        var annotationView = self.mapView.dequeueReusableAnnotationView(withIdentifier: "CustomPin")
        if annotationView == nil{
            annotationView = AnnotationView(annotation: annotation, reuseIdentifier: "CustomPin")
            annotationView?.canShowCallout = false
        }else{
            annotationView?.annotation = annotation
        }
        annotationView?.image = UIImage(named: "bluecircle") // Pass name of your custom image
        return annotationView
    }
 func mapView(_ mapView: MKMapView,
             didSelect view: MKAnnotationView){ 
    let annotation = view.annotation as? CustomAnnotation
   print(annotation?.address) // get info you passed on pin

  // write code here to add custom view on tapped annotion

}

于 2018-07-26T12:58:22.733 回答