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

发布于 2024-10-09 00:17:53 字数 1850 浏览 0 评论 0原文

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

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

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

    }

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;

    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人生戏 2024-10-16 00:17:53

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

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

Add this to the top of the viewForAnnotation method:

if ([annotation isKindOfClass:[MKUserLocation class]])
    return nil;  //return nil to use default blue dot view
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文