Reputation: 706
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.
Upvotes: 0
Views: 172
Reputation: 11770
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.
Upvotes: 1