Tôi đã có một MapView đó sẽ phóng to vị trí hiện tại sử dụng viewDidLoad
:Đến/zoom với chức năng hiện tại vị trí (MapKit)
#define METERS_PER_MILE 1609.344
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
mapView.showsUserLocation=TRUE;
// zoom to a specific area
CLLocationCoordinate2D zoomLocation;
zoomLocation.latitude = -28.994167;
zoomLocation.longitude = 134.866944;
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, 1900*METERS_PER_MILE, 1900*METERS_PER_MILE);
MKCoordinateRegion adjustedRegion = [mapView regionThatFits:viewRegion];
// make sure the Google water mark is always visible
mapView.autoresizingMask =
(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
[mapView setRegion:adjustedRegion animated:YES];
mapView.delegate=self;
searchBar.delegate = self;
}
này hoạt động tốt. Tôi đã thêm một thanh tìm kiếm và một hàm để chuyển đến một vị trí địa chỉ cụ thể. Điều này cũng tốt. Bây giờ tôi muốn thêm một nút để quay lại vị trí hiện tại. Bạn có thể cho tôi một tay không?
Chúc mừng
là có một chức năng gọi là setCenter? – carbonr
@carbonr yes, có –
[mapView setCenterCoordinate: mapView.userLocation.location.coordinate animated: YES]; – carbonr