我使用應用中的地圖製作應用,並使用按鈕更改爲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];
爲視圖的代碼是:
- (void)viewDidLoad {
[super viewDidLoad];
UIImage *image = [UIImage imageNamed: @"LogoNavBar.png"];
UIImageView *imageview = [[UIImageView alloc] initWithImage: image];
UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithCustomView: imageview];
self.navigationItem.rightBarButtonItem = button;
[imageview release];
[button release];
locationManager=[[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
mapView.showsUserLocation = YES;
NSLog(@"storedLocation-latitude für MKregion: %f", storedLocation.latitude);
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];
MKCoordinateRegion hotel;
hotel.center.latitude = 45.58058;
hotel.center.longitude = -0.546835;
HotelPositionMarker* marker = [[HotelPositionMarker alloc] initWithCoordinate:hotel.center];
[mapView addAnnotation:marker];
[marker release];
}
我的問題:當 「viewDidLoad中」 啓動時, 「storedLocation」 仍然是0.0000它需要更長的時間才能獲得自己的位置,而不是啓動視圖。 「viewDidLoad」部分中的「storedLocation」的日誌爲0,而當地圖可見時「 - (IBAction)」中的「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];
是爲零:( 但我怎麼能管理等是否有一個代碼存在於viewDidLoad中實施,以間隔2秒 – Christian 2010-04-06 13:15:39
我的意思是等待'didUpdateToLocation:'被調用執行的其他在'viewDidLoad'中的東西,例如顯示一個旋轉活動指示器,直到第一次調用'didUpdateToLocation:' – 2010-04-06 13:19:38
我試過沒有任何成功,我從viewDidLoad改成了viewWillAppear,在這種情況下,當你回到菜單並在一秒鐘內再次調用視圖,當前位置將顯示正確。但這不是解決方案.... – Christian 2010-04-06 18:27:16