2012-09-05 160 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

相关问题