【发布时间】:2011-08-11 07:37:39
【问题描述】:
我是 MapKit 及其所有功能的新手,因此一直在尝试显示图钉。我遵循了一个在线视频教程,介绍了如何找到用户当前位置并在那里放置一个图钉。但是当我输入引脚的方法时,我根本不明白。我想知道我哪里做错了。
- (void)viewDidLoad{
[super viewDidLoad];
self.title = @"Location";
mapView.showsUserLocation = YES;
self.locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
[locationManager startUpdatingHeading];
}
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{
NSLog(@"Annotation view run");
MKPinAnnotationView *pin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
pin.animatesDrop = YES;
return pin;
}
-(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
// once location is determined, center to that location.
location = newLocation.coordinate;
MKCoordinateRegion region;
region.center = location;
MKCoordinateSpan span;
span.latitudeDelta = 0.003;
span.longitudeDelta = 0.003;
region.span = span;
[mapView setRegion:region animated:FALSE];
}
任何关于我哪里做错的建议都会很棒!
【问题讨论】:
-
您的日志中是否曾经显示过“注释视图运行”?
-
不,甚至没有调用该方法。
-
你在.h文件中设置了MKMapViewDelegate吗?
-
是的,我也有,包括 CLLocationManagerDelegate。