0

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.

Nikunj Jadav
  • 3,417
  • 7
  • 38
  • 54

2 Answers2

2

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.

Craig
  • 8,093
  • 8
  • 42
  • 74
  • You could use an MKAnnotation if you're happy with Apple's styling, or make a custom subclass as explained here: http://stackoverflow.com/questions/2342070/how-to-add-more-details-in-mkannotation-in-iphone-os That answer links to sample code from apple: http://developer.apple.com/iphone/library/samplecode/WeatherMap/index.html – Craig Aug 07 '11 at 20:58
  • If my answer helped you it'd be good to get it marked accordingly – Craig Aug 18 '11 at 01:08
0

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)
}
B.Dhruvin
  • 31
  • 7