我有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分鐘,我怎麼能解決這個問題?