【发布时间】:2010-12-22 20:26:14
【问题描述】:
我不知道为什么当前位置圈不会出现。我有自定义注释,看起来很好......地图被带到用户的当前位置......但是,圆圈没有出现。
这是我的代码。提前致谢!
- (void)viewDidLoad {
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager startUpdatingLocation];
[mapView setMapType:MKMapTypeStandard];
mapView.showsUserLocation = YES;
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.span.longitudeDelta = 0.005;
region.span.latitudeDelta = 0.005;
[mapView setRegion:region animated:YES];
[mapView setDelegate:self];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
CLLocationCoordinate2D loc = [newLocation coordinate];
[mapView setCenterCoordinate:loc];
}
-(MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation {
static NSString *AnnotationViewID = @"annotationViewID";
MKAnnotationView *annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
if (annotationView == nil) {
annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
}
annotationView.canShowCallout = YES;
if ([annotationView.annotation.title isEqualToString:@"One"]) {
UIImage *pinImage = [UIImage imageNamed:@"one.png"];
[annotationView setImage:pinImage];
}
if ([annotationView.annotation.title isEqualToString:@"Two"]) {
UIImage *pinImage = [UIImage imageNamed:@"two.png"];
[annotationView setImage:pinImage];
}
annotationView.annotation = annotation;
return annotationView;
}
【问题讨论】:
-
你是在设备上测试还是在模拟器上测试?在模拟器中,用户的位置始终位于加利福尼亚州库比蒂诺。
-
显示你的 viewForAnnotation 方法。
-
@ezekielDFM 我正在使用设备和模拟器。用户位置也不会出现在 Cupertino 中。 @aBitObvious 我更新了我原来的问题。
标签: iphone iphone-sdk-3.0 ios4 mapkit android-mapview