iphone:如何在 MKAnnotation 视图中使用地图图钉上的索引号?

发布于 2024-11-28 13:29:37 字数 105 浏览 2 评论 0原文

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

提前致谢。

Hello friends,
I am developing a functionality to display index number on map pin and set image on mapview of iPhone so please tell me any link or any idea to develop this functionality.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

染墨丶若流云 2024-12-05 13:29:37

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

What is an index number in the context? Is it just a digit that your code is displaying? If so your question is how to display text on a map. Use a map overlay. Same for images. Search for MKMapOverlay and go from there.

夏夜暖风 2024-12-05 13:29:37

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

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)
}

I have use this method for index number in annotation view.

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)
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文