Iphone 当前位置太慢,无法查看

Iphone 当前位置太慢,无法查看,iphone,xcode,iphone-sdk-3.0,map,Iphone,Xcode,Iphone Sdk 3.0,Map,我制作了一个应用程序,应用程序中有一张地图,还有一个按钮可以切换到google.Map-App 我的职位代码是: -(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { float avgAccuracy = (newLocation.verticalAccura

我制作了一个应用程序,应用程序中有一张地图,还有一个按钮可以切换到google.Map-App

我的职位代码是:

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

float avgAccuracy = (newLocation.verticalAccuracy + newLocation.horizontalAccuracy)/2.0;


if (avgAccuracy < 500) {
    [locationManager stopUpdatingLocation];
    locationManager.delegate = nil;
}


storedLocation = [newLocation coordinate];
我的问题是:当viewDidLoad启动时,storedLocation仍然是0.0000。获取自己的位置所需的时间比启动视图所需的时间稍长。viewDidLoad部分中storedLocation的日志为0,而当映射可见时,-iAction中storedLocation的日志包含正确的值

如何在加载视图之前获取坐标?我需要他们把自己的立场和我给出的立场放在中心

MKCoordinateRegion region;
region.center.latitude = (storedLocation.latitude + 45.58058)/2.0;
region.center.longitude = (storedLocation.longitude - 0.546835)/2.0;
region.span.latitudeDelta = ABS(storedLocation.latitude - 45.58058);
region.span.longitudeDelta = ABS(storedLocation.longitude + 0.546835);
[mapView setRegion:region animated:TRUE];
尝试获取locationManager.location的值作为初始值,但该值可能很旧,甚至可能为零


如果需要当前位置,则必须等待CLLocationManager。甚至谷歌地图应用程序在显示您的位置之前也会等待几秒钟。

在使用地图调用viewController之前,请先调用locationManager。并将locationManager作为正在初始化和推送的viewController的成员变量传递。 如果这是您的第一个视图,请在委托中构建它。
这行得通吗?

是零:但我怎么能等呢?是否存在要在viewDidLoad中实现等待2秒的代码?我的意思是等待调用didUpdateToLocation:。在viewDidLoad中执行其余的操作,例如显示一个旋转活动指示器,直到第一次调用didUpdateToLocation:为止。我从viewDidLoad更改为ViewWillDisplay。在这种情况下,当您返回菜单并在一秒钟内再次调用视图时,当前位置将正确显示。但这不是解决办法……看来我还没有说清楚。你必须做任何你正在做的事情,以视图为中心吗?在viewDidLoad或ViewDidDisplay中?只需在didUpdateToLocation:中执行即可。
MKCoordinateRegion region;
region.center.latitude = (storedLocation.latitude + 45.58058)/2.0;
region.center.longitude = (storedLocation.longitude - 0.546835)/2.0;
region.span.latitudeDelta = ABS(storedLocation.latitude - 45.58058);
region.span.longitudeDelta = ABS(storedLocation.longitude + 0.546835);
[mapView setRegion:region animated:TRUE];