我有view1
,其中有button1
,当button 1
用户点击,用户的当前位置进行跟踪和第二视图view2
所示,其中用户设置自己的搜索参数并点击button2
,当点击button2
时,将显示一个视图view3
,其中显示一个地图。地图只显示如果我等待至少1分钟
现在我的问题是,如果用户至少等待1分钟,然后点击button2
,地图显示得相当好,否则地图不会显示。 我对view2
相关代码:
- (void)viewDidLoad {
//when this view is loaded, the user current location is tracked
self.locationManager=[[CLLocationManager alloc]init];
[locationManager setDelegate:self];
[locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
[locationManager startUpdatingLocation];
}
#pragma mark-
#pragma mark CLLocationManagerDelegate
-(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
float latitude=newLocation.coordinate.latitude;
float longitude=newLocation.coordinate.longitude;
TopStationAppDelegate *topStation=(TopStationAppDelegate *)[[UIApplication sharedApplication]delegate];
topStation.latitudeUtilisateur=latitude;
topStation.longitudeUtilisateur=longitude;
NSLog(@"%f",latitude);
NSLog(@"%f",longitude);
[locationManager stopUpdatingLocation];
}
我在view3
这使问题代码:
-(void)viewWillAppear:(BOOL)animated
{
//here is the problem:
//if the user wait 1 minute before coming to this view, I mean before clicking on button2
//this view shows the map pretty well, otherwise the map is not displayed and I got brown //screen
[mapView removeAnnotations:mapView.annotations];
[mapView setMapType:MKMapTypeStandard];
TopStationAppDelegate *topStation=(TopStationAppDelegate *)[[UIApplication sharedApplication]delegate];
latitudeOfUserLocation=topStation.latitudeUtilisateur;
longitudeOfUserLocation=topStation.longitudeUtilisateur;
}
我为什么要等待1分钟,我怎么能解决这个问题?