非常多的新手在這裏,請原諒無知。我花了一些時間試圖瞭解我失蹤的東西,但無法弄清楚。如何在特定位置居中,然後放大到當前位置
我的應用程序在加載時在華盛頓州的中心,但是當我嘗試縮放到用戶當前位置時,它將我置於北緯0經度0.如果我註釋掉「//啓動:WA中心」部分,用戶當前的位置,然後goToLocation工作正常。
我該如何讓它在華盛頓州的中心,然後在點擊goToLocation後縮放到用戶當前位置?
謝謝!
- (void)viewDidLoad {
[super viewDidLoad];
[self loadOurAnnotations];
[mapView setShowsUserLocation:NO];
// startup: center over WA
CLLocationCoordinate2D defaultCoordinate;
defaultCoordinate.latitude = 47.517201;
defaultCoordinate.longitude = -120.366211;
[mapView setRegion:MKCoordinateRegionMake(defaultCoordinate, MKCoordinateSpanMake(6.8, 6.8)) animated:NO];
}
-(IBAction)goToLocation {
MKUserLocation *myLocation = [mapView userLocation];
CLLocationCoordinate2D coord = [[myLocation location] coordinate];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(coord, 350, 350);
[mapView setRegion:region animated:YES];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView commitAnimations];
}
非常感謝你的幫助,安娜。我會修補這個。 – Rick