我有代码获取用户位置并显示在mapView上,但他们必须缩小并在地图上找到自己,我想要的是当按钮按下时,它自动将它们带到它们所在的位置。下面是我到目前为止的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
MKCoordinateRegion bombersRegion = { {0.0,0.0}, {0.0,0.0} };
bombersRegion.center.latitude = 42.812548;
bombersRegion.center.longitude = -73.940815;
bombersRegion.span.latitudeDelta = 0.01f;
bombersRegion.span.longitudeDelta = 0.01f;
[bombersMapView setRegion:bombersRegion animated:YES];
MapPin *ann = [[MapPin alloc] init];
ann.title = @"Bombers Burrito Bar";
ann.subtitle = @"447 State Street Schenectady, New York 12305";
ann.coordinate = bombersRegion.center;
[bombersMapView addAnnotation:ann];
}
-(IBAction)getLocation:(id)sender{
bombersMapView.showsUserLocation = YES;
}
谢谢你的帮助。
如果你想让地图保持在用户位置的中心,试试这个
[bombersMapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES];
看一下这个MKMapViewDelegate
方法。这将给你用户的位置,你可以用它来放大。您正在寻找的方法是mapView:didUpdateUserLocation:
。