How to set image on MKAnnotation in MKMapView

前端 未结 5 770
盖世英雄少女心
盖世英雄少女心 2021-01-06 23:53

I am developing an app for chating, I have to display all friends on a Map with their image. Please provide guidance to implement it.

I have used following code...

5条回答
  •  悲哀的现实
    2021-01-07 00:04

    Pleae use the below code.

    - (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id )annotation 
    {
        if ([annotation isKindOfClass:[MKUserLocation class]]) {
            return nil;
        }
    
        static NSString* MapAnnotationIdentifier = @"MapAnnotationIdentifier";
        MKAnnotationView* pinView = (MKAnnotationView *)[quakesMapView dequeueReusableAnnotationViewWithIdentifier:MapAnnotationIdentifier];  
    
        if (!pinView) {
            pinView = [self annotationViewForAnnotation:annotation withIdentifier:MapAnnotationIdentifier];
        }
    
     pinView.image = [UIImage imageNamed:YourImage];
    
        return pinView;
    
    }
    

提交回复
热议问题