我有哪些縮放到使用viewDidLoad
當前位置的MapView類:轉至/縮放到當前位置的功能(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;
}
這工作得很好。我添加了一個搜索欄和一個功能來跳轉到特定的地址位置。這工作也很好。我現在想添加一個按鈕跳回到當前位置。你能幫我一下嗎?
乾杯
添加
yourMKMapView.showsUserLocation = true
是有一個叫setCenter功能? – carbonr@carbonr是的,有 –
[mapView setCenterCoordinate:mapView.userLocation.location.coordinate animated:YES]; – carbonr