0

I am a newbie to mapkit. I followed a tutorial and used that code in my project.

I want to display an image instead of pin, and that image is in resources folder. How am I supposed to get that in there?

Thanks

Code so far:

viewDidLoad method of NewMapViewController:

MKCoordinateRegion region;
region.center.latitude=/*latitude*/;
region.center.longitude=/*longitude*/;
region.span.longitudeDelta=0.01;
region.span.latitudeDelta=0.01;
[mapview setRegion:region animated:YES];
MapAnnotation *ann=[[MapAnnotation alloc]init];
ann.title=@"MLeaf";
ann.subtitle=@"Headquarters";
ann.coordinate=region.center;
[mapview addAnnotation:ann];

MapAnnotationView *ann1=[[MapAnnotationView alloc]initWithAnnotation:ann reuseIdentifier:YES];
ann1.canShowCallout=YES;
ann1.img=[UIImage imageNamed:@"eg.png"];

I have initialized title and subtitle in MapAnnotation and have initialized canShowCallout and img in MapAnnotationView

Is this correct way? My app crashes because of NSInvalidArgumentException on the line where I initialize MapAnnotationView in viewdidload.

Jsdodgers
  • 5,253
  • 2
  • 20
  • 36
sin
  • 726
  • 7
  • 16
  • 1
    When people give you useful answers to your questions, please upvote the answers, or **accept** them, using the little icons to the left of each answer. Thanks. – Nate Sep 26 '12 at 08:57

1 Answers1

1

Check this How do I add custom pins to the iPhone MapKit? and iOS MapKit custom pins. Mainly, you have to initialize the map annotation view in delegate method(-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation) of map view.

Community
  • 1
  • 1
Fahri Azimov
  • 11,470
  • 2
  • 21
  • 29
  • so do you mean i should initialize the above delegate method in newmapviewcontroller? – sin Sep 26 '12 at 09:19