mapkit iphone中的图像

时间:2012-09-26 07:50:48

标签: ios mapkit

我是mapkit的新手。我按照教程在项目中使用了该代码。

我想显示图像而不是图钉,并且该图像位于资源文件夹中。 我怎么能在那里得到它?

由于

到目前为止

代码:

viewDidLoad

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"];

我在MapAnnotation中初始化了标题和副标题,并在MapAnnotationView中初始化了canShowCallout和img

这是正确的方法吗?我的应用程序崩溃是因为我在viewdidload中初始化MapAnnotationView的行上有NSInvalidArgumentException

1 个答案:

答案 0 :(得分:1)

选中How do I add custom pins to the iPhone MapKit?iOS MapKit custom pins。主要是,您必须在地图视图的委托方法(-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation)中初始化地图注释视图。