【问题标题】:iphone:How to use index number on map pin in MKAnnotation View?iphone:如何在 MKAnnotation 视图中使用地图引脚上的索引号?
【发布时间】:2011-08-05 07:43:17
【问题描述】:

朋友们好, 我正在开发一种功能来在地图图钉上显示索引号并在 iPhone 的地图视图上设置图像,所以请告诉我任何链接或任何想法来开发此功能。

提前致谢。

【问题讨论】:

    标签: mkmapview


    【解决方案1】:

    上下文中的索引号是什么?您的代码显示的只是一个数字吗?如果是这样,您的问题是如何在地图上显示文本。使用地图叠加层。图像也一样。搜索 MKMapOverlay 并从那里开始。

    【讨论】:

    【解决方案2】:

    我已经在注释视图中使用此方法作为索引号。

    func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
    
            guard !(annotation is MKUserLocation) else {
                return nil
            }
    
    
            // Better to make this class property
            let annotationIdentifier = "AnnotationIdentifier"
            var annotationView = MKAnnotationView()
            annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier)
            annotationView.frame = CGRect(x: annotationView.frame.origin.x, y: annotationView.frame.origin.y, width: 80, height: 200)
            annotationView.annotation = annotation
            annotationView.tag = index
            index += 1
    
            let imageViewPin = UIImageView(frame: CGRect(x: 0, y: 0, width: 30, height: 40))
            imageViewPin.center = CGPoint(x: annotationView.center.x, y: annotationView.center.y - 11)
            imageViewPin.image = UIImage(named: "green_pin")
            annotationView.addSubview(imageViewPin)
    
            return annotationView
        }
    
    func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
    
            debugPrint(view.tag)
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-13
      • 2017-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-03
      • 2011-12-31
      • 1970-01-01
      相关资源
      最近更新 更多