繁体   English   中英

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

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

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

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

- (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方法的顶部:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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