MapKit用户位置(蓝点和圆圈)将不会显示

时间:2010-12-22 20:26:14

标签: iphone iphone-sdk-3.0 ios4 mapkit android-mapview

我无法弄清楚为什么当前的位置圈不会出现。我有自定义注释看起来很好......地图被带到用户的当前位置......但是,圆圈​​没有出现。

这是我的代码。提前谢谢!

- (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;

    }

1 个答案:

答案 0 :(得分:27)

将其添加到viewForAnnotation方法的顶部:

if ([annotation isKindOfClass:[MKUserLocation class]])
    return nil;  //return nil to use default blue dot view