简体   繁体   中英

MapKit User Location (Blue Dot & Circle) will not show

I cannot figure out why the current location circle will not appear. I have custom annotations that appear just fine... and the map is taken to the current location of the user... but, the circle is not appearing.

Here is my code. Thanks in advance!

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

    }

Add this to the top of the viewForAnnotation method:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM