需要帮助的地图自动打开注释标注,地图的时候第一次加载 [英] Need help opening callout of annotation on map automatically, when map first loads

查看:165
本文介绍了需要帮助的地图自动打开注释标注,地图的时候第一次加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iPhone亲爱的同学/ Objective-C的开发:

Dear fellow iPhone/Objective-C developers:

我的iPhone,我的工作,允许用户从表中查看选择,地图上的导航应用的基础。我有在地图上精确定位用户所选择的位置的注释。按正常的行为,如果用户点击标注,标注出现有关位置的详细信息。这里没有问题。我的问题是,我想标注来自标注自动出现,一旦用户被带到屏幕包含地图,让用户不必点击注释才能看到有关位置的细节,但我不知道如何做到这一点。我有下面的方法在我的的MapViewController级,在其中执行地图显示的大部分工作:

I have a navigation based application for the iPhone that I am working that allows the user to view a selection from a table, on a map. I have an annotation that pinpoints the user's selected location on the map. As per normal behaviour, if the user clicks on the annotation, a callout appears with the details about the location. No problems here. My question is, I'd like the callout to appear automatically from the annotation, once the user is taken to the screen containing the map, so that the user does not have to click on the annotation in order to see the details about the location, but I'm not sure how to do this. I have the following method in my "MapViewController" class, where the bulk of the map display work is performed:

- (void)viewDidLoad {

   [super viewDidLoad];
MKCoordinateRegion region;
MKCoordinateSpan span;

NavButtonAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
userCoord = delegate.userLocation.coordinate;

region.center = userCoord; 
span.latitudeDelta = 0.4;
span.longitudeDelta = 0.4;
region.span = span;

[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
mapView.showsUserLocation = YES;
[mapView setRegion:region animated:YES]; 

RestaurantAnnotation *rAnnotation = [[RestaurantAnnotation alloc] init];
rAnnotation.title = restaurantObj.name;  
rAnnotation.subtitle = restaurantObj.address;
rAnnotation.subtitle = [restaurantObj.address stringByAppendingFormat:@" %@", restaurantObj.hours]; 
rAnnotation.subtitle = [restaurantObj.address stringByAppendingFormat:@" %@", restaurantObj.phoneNumber]; 


CLLocationCoordinate2D newCoord = {restaurantObj.latitude, restaurantObj.longitude};
rAnnotation.coordinate = newCoord;
[mapView addAnnotation:rAnnotation];

}

本的MapViewController从在previous屏幕下面的方法叫做:

The MapViewController is called from the following method in the previous screen:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

Restaurant *rLocation = [restaurantList objectAtIndex:indexPath.row];

MapViewController *mapController = [[MapViewController alloc] initWithRestaurant:rLocation];
[self.navigationController pushViewController:mapController animated:YES];
[mapController release];

}

我意识到,我必须用下面的方法来实现:

I realize, that I have to use the following method to accomplish this:

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
    id<MKAnnotation> myAnnotation = [mapView.annotations objectAtIndex:0];
    [mapView selectAnnotation:myAnnotation animated:YES];
}

不过,我不知道怎么样。我没有,我用一下子很多注解,我只有一个注解,我需要这样的工作。

However, I'm not sure how. I don't have many annotations that I am using all at once, I only have one annotation that I need this to work with.

我在哪里可以把这个方法在我的应用程序,以及我在哪里把它来自哪里?

我称从viewDidLoad方法这个方法,并把实际的方法,我的MapViewController类中?

Where do I put this method in my app, and where do I call it from?
Do I call this method from the viewDidLoad method and put the actual method inside my MapViewController class?

在此先感谢所有谁答复。

Thanks in advance to all who reply.

推荐答案

您必须添加

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views { 
    id myAnnotation = [mapView.annotations objectAtIndex:0]; 
    [mapView selectAnnotation:myAnnotation animated:YES]; 
}

您设置为代表的的MKMapView类。

to the class that you set as the delegate for the MKMapView.

这篇关于需要帮助的地图自动打开注释标注,地图的时候第一次加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆