I have an MKMapView, and I'm trying to set the map, so that when you first load the application it goes to a user set location, and if the user hasn't set one, to a default one. The problem is that it always seems to go to 0 latitude, 0 longitude.
-(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];
}
I've tried setting setShowUserLocation
to NO
, but that doesn't work. I know it's reading the correct region, because the NSLog
is outputing the default latitude, but the map insists on going to somewhere in China...
I've also tried setting the region in mapView:didUpdateUserLocation:
, but still the same result.
What am I doing wrong?
EDIT: I added the NSLog
to output the longitude as well. The output is:
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