我很困惑。我有一个 MKMapView,在 viewDidLoad 方法中我做了:
- (void)viewDidLoad {
mainDelegate = (PublicArtOmahaAppDelegate*)[[UIApplication sharedApplication]delegate];
XMLController *myXMLController = [[XMLController alloc] init];
[myXMLController parse];
mapView.showsUserLocation = YES;
[self gotoLocation];
// add annotations to map
[self.mapView addAnnotations:mainDelegate.mapAnnotations];
[myXMLController release];
}
[self gotoLocation] 调用:
- (void)gotoLocation
{
MKCoordinateRegion newRegion;
CLLocation *userLocation = mapView.userLocation.location;
float latitude = userLocation.coordinate.latitude;
float longitude = userLocation.coordinate.latitude;
newRegion.center.latitude = latitude;
newRegion.center.longitude = longitude;
[self.mapView setRegion:newRegion animated:YES];
}
所以我认为这应该在 mapView 加载时将地图集中在用户的位置上,并且我还计划在屏幕上实现一个按钮,该按钮将再次手动调用 gotoLocation 以在用户需要时更新用户的位置。
但是......当我在设备上运行该应用程序时,它会加载以非洲西部一片海洋为中心的地图,该海域显然是经纬度 0,0。我觉得奇怪的是,当我放大到我的真实位置时,它已经正确地将我的位置作为注释放置了。所以我想我在 gotoLocation 中设置用户位置的方式有问题吗?有人注意到我做错了什么吗?