【问题标题】:MapKit User Location (Blue Dot & Circle) will not showMapKit 用户位置(蓝点和圆圈)将不显示
【发布时间】: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


【解决方案1】:

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

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

【讨论】:

  • @Anna Karenina 在设备中,没有出现闪烁的圆圈,但只显示当前位置的蓝点,在模拟器中它工作正常,所以请给我一些想法
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-25
  • 1970-01-01
  • 1970-01-01
  • 2015-07-27
相关资源
最近更新 更多