0

我有一个 MKMapView,我正在尝试设置地图,这样当您第一次加载应用程序时,它会转到用户设置的位置,如果用户没有设置,则转到默认位置。问题是它似乎总是去 0 纬度,0 经度。

-(void) viewDidLoad {

  [worldView setShowsUserLocation:YES];

  double longitude = [[NSUserDefaults standardUserDefaults] doubleForKey:WhereamiNewLongPrefKey];

  double latitude = [[NSUserDefaults standardUserDefaults] doubleForKey:WhereamiNewLatPrefKey];

  CLLocationCoordinate2D savedLoc = CLLocationCoordinate2DMake(latitude, longitude);

  MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(savedLoc, 250, 250);

  NSLog(@"latitude :%f", region.center.latitude);      
  NSLog(@"longitude :%f", region.center.longitude);

  [worldView setRegion:region animated:YES];
}

我尝试设置setShowUserLocationNO,但这不起作用。我知道它正在读取正确的区域,因为它NSLog正在输出默认纬度,但地图坚持要去中国的某个地方......

我也尝试将区域设置为mapView:didUpdateUserLocation:,但结果仍然相同。

我究竟做错了什么?

编辑:我也添加了NSLog输出经度。输出是:

2012-11-14 09:50:30.699 Whereami[34256:13d03] latitude :20.516700
2012-11-14 09:50:30.699 Whereami[34256:13d03] longitude :99.900000
4

1 回答 1

0
CLLocationCoordinate2D theCoordinate;
theCoordinate.latitude = 20.516700;
theCoordinate.longitude = 99.900000;

MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(theCoordinate, 1000, 1000);
MKCoordinateRegion adjustedRegion = [self.mapView regionThatFits:viewRegion];  
[self.mapView setRegion:adjustedRegion animated:YES];
于 2012-11-14T16:41:15.567 回答