使用 mkmap 加载地图时显示标题
我能够在 iphone 应用程序项目中显示地图并在所需位置放置图钉,但我希望在视图加载时显示标题和副标题。这是我正在使用的代码。我以为放入 [mapView selectAnnotation:注释动画:是];
会起作用,但事实并非如此。有谁知道该怎么做?
谢谢
CLLocationCoordinate2D coord = {纬度:32.02008,经度:-108.479707};
[self.view addSubview:mapView];
MapController *annotation = [[MapController alloc] initWithCoordinate:coord];
annotation.currentPoint = [NSNumber numberWithInt:1];
annotation.mTitle = @"MyTitle";
annotation.mSubTitle = @"My Address";
[mapView selectAnnotation:annotation animated:YES];
[mapView addAnnotation:annotation];
[annotation release];
I am able to get a map to show up and a pin to drop where I want in my iphone app project, but I want the title and subtitle to appear when the view loads. Here is the code I'm using. I thought putting in
[mapView selectAnnotation:annotation animated:YES];
would work, but it doesn't. Does anyone know how to do this?
Thanks
CLLocationCoordinate2D coord = {latitude: 32.02008, longitude: -108.479707};
[self.view addSubview:mapView];
MapController *annotation = [[MapController alloc] initWithCoordinate:coord];
annotation.currentPoint = [NSNumber numberWithInt:1];
annotation.mTitle = @"MyTitle";
annotation.mSubTitle = @"My Address";
[mapView selectAnnotation:annotation animated:YES];
[mapView addAnnotation:annotation];
[annotation release];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在将其添加到地图之前调用 selectAnnotation 将不起作用,甚至将其放在 addAnnotation 行之后也不起作用,因为注释视图尚未绘制在地图上。
您需要使用 didAddAnnotationViews 委托方法,该方法在注释准备好操作时调用:
该示例仅假设您有一个注释并从 mapView 的注释数组中获取它。您还可以使用 ivar 保存对注释的引用。
确保您已经设置了mapView的委托属性,否则该方法将不会被调用。
Calling selectAnnotation before it's added to the map won't work and even putting it after the addAnnotation line will not work because the annotation view hasn't been drawn on the map yet.
You'll need to use the didAddAnnotationViews delegate method which is called when annotations are ready to manipulate:
The example just assumes you have one annotation and gets it from the mapView's annotations array. You could also hold a reference to your annotation with an ivar.
Make sure you have set the mapView's delegate property otherwise the method won't be called.