0

我是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

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

4

1 回答 1

1

检查此如何将自定义引脚添加到 iPhone MapKit?iOS MapKit 自定义引脚。主要是,您必须在地图视图的委托方法(-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation)中初始化地图注释视图。

于 2012-09-26T08:15:33.010 回答