没有立即调用ClLocationManager委托?

时间:2012-09-05 15:02:34

标签: iphone objective-c ios

我正在尝试使用cllocationmanager获取当前位置。

问题:

委托方法

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

始终在viewdidappear之后运行。我在viewDidLoad中启动了bitdatingLocation。并在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 个答案:

答案 0 :(得分:1)

didUpdateToLocation 方法中调用 setMapView 方法,前提是您将位置管理员委托设置为 self 并添加 CLLocationManagerDelegate 在你的.h文件中。在didUpdateToLocation中,在调用setMapView方法之前,将newLocation坐标分配给currentLocation坐标。