【问题标题】:Xcode 4.3.3 Mapview, annotation not showingXcode 4.3.3 Mapview,注释未显示
【发布时间】:2012-06-30 17:22:27
【问题描述】:

我的注释 (homeMark) 没有显示在 mapView 中。 我在 IB 中做了我的 viewController 委托

由于某种原因在委托方法中 if ([annotation isKindOfClass:[HomeMark class]]) {

失败.....注释不是“Homemark”类的一部分...

我做错了什么?

代码...

- (IBAction)clubHouse:(id)sender{
    MKCoordinateRegion region = { {0.0, 0.0 } , {0.0,0.0} };
    region.center.latitude = 55.305858;
    region.center.longitude = 12.386036;


    CLLocationCoordinate2D coord = {
        .latitude = region.center.latitude, 
        .longitude = region.span.longitudeDelta};

    HomeMark *homeMark = [[HomeMark alloc] 
                          initWithCoordinate:coord 
                          andMarkTitle:@"Klubhus" 
                          andMarkSubTitle:@"Stevns Cykel Motion"];

    [mapMyView addAnnotation:homeMark];

    [mapMyView setMapType:MKMapTypeStandard];
    [mapMyView setZoomEnabled:YES];
    [mapMyView setScrollEnabled:YES];
    region.span.longitudeDelta = 0.007f;
    region.span.latitudeDelta = 0.007f;
    [mapMyView setRegion:region animated:YES];
    //[mapMyView setDelegate:sender];    
    mapMyView.showsUserLocation = YES;

}

还有 ViewForAnnotation。

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {

    static NSString *identifier = @"MyLocation";
    if ([annotation isKindOfClass:[HomeMark class]]) {

        MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
        if (annotationView == nil) {
            annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
        }
        else {
            annotationView.annotation = annotation;
        }

        annotationView.enabled = YES;
        annotationView.canShowCallout = YES;

        return annotationView;
    }

    return nil; 
}

【问题讨论】:

  • 我仍然不明白为什么人们投反对票,也没有说为什么...... Stackoverflow 只是充满了巨魔吗?

标签: objective-c annotations mkmapview mkannotationview


【解决方案1】:

您似乎错误地指定了坐标,因此注释不在您期望的位置。

而不是这个:

CLLocationCoordinate2D coord = {
    .latitude = region.center.latitude, 
    .longitude = region.span.longitudeDelta};  // <-- span doesn't make sense

试试这个:

CLLocationCoordinate2D coord = {
    .latitude = region.center.latitude, 
    .longitude = region.center.longitude};  // <-- not span

【讨论】:

  • 非常感谢,我不敢相信我没有看到这个。开启“自动完成”并不总是一个好主意。再次感谢:-D
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-04-06
  • 2023-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多