2012-09-05 218 views
0

我想使用cllocationmanager來獲取我當前的位置。ClLocationManager委託沒有被立即調用?

問題:

委託方法

-(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 

總是viewdidappear後運行。我在viewDidLoad中啓動了位置。並在viewdidLoad的末尾調用SetMapView方法。

-(void)setMapView{ 

MKCoordinateRegion zoomIn = plotsMapView.region; 
zoomIn.span.latitudeDelta = 0.2; 
zoomIn.span.longitudeDelta = 0.2; 



zoomIn.center.latitude = self.currentLocation.coordinate.latitude;//[[[m_CityMarkerArray objectAtIndex:0] valueForKey:@"lat"] doubleValue]; 
zoomIn.center.longitude = self.currentLocation.coordinate.longitude;//[[[m_CityMarkerArray objectAtIndex:0] valueForKey:@"lng"] doubleValue]; 



NSLog(@"%f LAT",self.currentLocation.coordinate.latitude); 

[plotsMapView setRegion:zoomIn animated:YES]; 



} 

該LAT返回0.0000。

但如果我在viewDidAppear中調用相同的方法,它工作正常。 我需要它在viewdidload中,因爲每次我回來查看。如果我調用viewDidAppear中的方法,我會將地圖重新​​加載到基本位置。

請幫忙! 謝謝!

回答

1

打電話給你setMapView方法內didUpdateToLocation方法,只要你的位置管理委託設置爲自我並在.h文件中添加CLLocationManagerDelegate。在你的didUpdateToLocation中,在調用你的setMapView方法之前,將newLocation座標分配給你的currentLocation座標。

+0

謝謝!不知道爲什麼我想到它:| –

+0

不客氣 – Neo

相關問題