【发布时间】:2010-04-06 10:42:40
【问题描述】:
我制作了一个App,在App里面有一个地图,还有一个按钮可以改成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”的 Log 为 0,而“-(IBAction)”中的“storedLocation”的 Log 包含正确的值。
如何管理它以在视图加载之前获得我的坐标?我需要他们把关于自己的立场和我给出的立场的观点集中起来。
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];
【问题讨论】:
标签: iphone xcode iphone-sdk-3.0 map