【发布时间】:2012-03-20 10:38:02
【问题描述】:
我想在 MKMapView 中添加一个功能。
我有一个带有许多注释的 mapView 现在我想要那个 .. 当我触摸任何注释时,整个视图都应该专注于该注释。即注释 A 在右上角,当我触摸 MapView 应该在中心显示 A 时。
【问题讨论】:
标签: iphone uiview annotations location mkmapview
我想在 MKMapView 中添加一个功能。
我有一个带有许多注释的 mapView 现在我想要那个 .. 当我触摸任何注释时,整个视图都应该专注于该注释。即注释 A 在右上角,当我触摸 MapView 应该在中心显示 A 时。
【问题讨论】:
标签: iphone uiview annotations location mkmapview
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
MKAnnotation *annotation= view.annotation; // Get your annotaion here
[map setCenterCoordinate:annotation.coordinate];
}
//This will set the annotation in the centre of the map without zooming the map.
【讨论】:
在 Annotation Delegate 中,您必须设置地图视图的区域,指定中心
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
MKAnnotation *annotation= view.annotation; // Get your annotaion here
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude=annotation.coordinate.latitude;
region.center.longitude=annotation.coordinate.longitude;
region.span.latitudeDelta=0.001f;
region.span.longitudeDelta=0.001f;
[mapView setRegion:region animated:YES];
//Do your other stuffs here
}
【讨论】: