1
我无法理解CLLocationManager如何获取我当前的位置坐标?如果我不调用[locationManager startUpdatingLocation]并且不在locationManager.location.coordinate中设置参数。locationManager如何获取坐标?
ViewController.h
@interface ViewController : UIViewController <MKMapViewDelegate, CLLocationManagerDelegate>
{
CLLocationManager *locationManager;
}
@property (weak, nonatomic) IBOutlet MKMapView* mapView;
@end
ViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
self.mapView.delegate = self;
[self.mapView setShowsUserLocation:YES];
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager setDistanceFilter:kCLDistanceFilterNone];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
}
-(void) mapView:(MKMapView *) mv didAddAnnotationViews:(NSArray *)views {
MKCoordinateRegion region;
region = MKCoordinateRegionMakeWithDistance(locationManager.location.coordinate, 1000, 1000);
[mv setRegion:region animated:YES];
}
目前尚不清楚你的问题是什么。我建议你编辑它以包含一个明确表示的问题,以便产生一个简明的答案。 –
它可能是先前执行的缓存值。查看locationManager.location.timestamp。它甚至可能是由将地图视图的showsUserLocation设置为YES引起的。另外,如果您使用地图视图来显示用户位置,则不需要CLLocationManager。 – Anna