我的应用上有一个MKMapView
。这是iOS6。
-(void)viewDidLoad
{
.....
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager setDesiredAccuracy:kCLLocationAccuracyBestForNavigation];
[locationManager setDistanceFilter:kCLDistanceFilterNone];
[locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
NSLog(@"Update locations is hit");
NSLog(@"379 the locations count is %d",locations.count);
CLLocation *obj = [locations lastObject];
NSLog(@"the lat is %f", obj.coordinate.latitude);
NSLog(@"the long is %f", obj.coordinate.longitude);
NSLog(@"the horizontal accuracy is %f",obj.horizontalAccuracy);
NSLog(@"the vertical accuracty is %f",obj.verticalAccuracy);
if (obj.coordinate.latitude != 0 && obj.coordinate.longitude != 0)
{
CLLocationCoordinate2D currrentCoordinates ;
currrentCoordinates.latitude = obj.coordinate.latitude;
currrentCoordinates.longitude = obj.coordinate.longitude;
}
....more computation
[locationManager stopUpdatingLocation];
}
当我第一次加载应用程序时,我的位置显示的距离不远。有时数英里之外。我还有一个重置位置按钮,如果我单击该地图会显示正确的位置。这就是我在重置位置按钮单击中的内容:
- (IBAction)btnResetLocationClick:(UIButton *)sender
{
locationManager = [[CLLocationManager alloc]init];
locationManager.delegate = self;
[locationManager setDesiredAccuracy:kCLLocationAccuracyBestForNavigation];
[locationManager setDistanceFilter:kCLDistanceFilterNone];
[locationManager startUpdatingLocation];
}
那么如何让应用程序在加载时获得正确的当前位置。有没有办法让应用程序告诉地图等待几毫秒然后更新。还是有其他想法?请告诉我。如果您需要更多信息,请询问。谢谢。