English 中文(简体)
当地图第一次加载时,如何自动打开地图上注释的标注?
原标题:How to open callout of annotation on map automatically, when map first loads?

我正在为iPhone开发一个基于导航的应用程序,它允许用户在地图上查看表格中的选择。我有一个注释,可以精确定位用户在地图上选择的位置。按照正常行为,如果用户单击注释,则会显示一个标注,其中包含有关位置的详细信息。这里没有问题。

我的问题是,一旦用户被带到包含地图的屏幕上,我希望标注能自动从注释中出现,这样用户就不必点击注释来查看有关位置的详细信息,但我不知道如何做到这一点。我在“MapViewController”类中有以下方法,其中执行了大部分地图显示工作:

- (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是从上一屏幕中的以下方法调用的:

- (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];
}

我意识到我必须使用以下方法来实现这一点:

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

但是,我不知道怎么做。我没有很多同时使用的注释,我只有一个需要使用的注释

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?

最佳回答

你必须添加

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

到您设置为MKMapView代理的类。

问题回答

暂无回答




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签