iOS MapView添加MKPointAnnotation,其坐标为(0,0)未显示

问题描述 投票:1回答:1

我想在MKMapView上添加注释。当坐标不是(0, 0)时,注释可以显示,但是当我将注释的坐标设置为(0,0)时,注释视图不会显示。

在iPhone XS模拟器和设备上,只显示一个注释(位置(10,0)),位置(0,0)不显示。

似乎(0,0)注释添加在地图的底部,而不是在非洲的西侧。

任何建议表示赞赏。

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    // Add Annotation
    MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
    annotation.coordinate = CLLocationCoordinate2DMake(0, 0);
    [self.mapView addAnnotation:annotation];
    MKPointAnnotation *annotationZero = [[MKPointAnnotation alloc] init];
    annotationZero.coordinate = CLLocationCoordinate2DMake(10, 0);
    [self.mapView addAnnotation:annotationZero];
}

#pragma mark - MKMapViewDelegate
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
    if ([annotation isKindOfClass:[MKPointAnnotation class]]) {
        static NSString *reuseIdentifier = @"map_annotation";
        MKAnnotationView *annotationView = [_mapView dequeueReusableAnnotationViewWithIdentifier:reuseIdentifier];
        if (annotationView == nil) {
            annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
        }
        annotationView.image = [UIImage imageNamed:@"annotation_icon"];
        return annotationView;
    }
    return nil;
}
ios objective-c mkmapview
1个回答
2
投票

我开始使用Swift测试并且CLLocationCoordinate2DMake(0,0)工作正常,因此问题与设备无关,但它是特定于语言的问题。

你不能在objective-c中使用(0,0),而是使用DBL_MIN,这是可能的最小数字,如下所示:

CLLocationCoordinate2DMake(DBL_MIN, DBL_MIN)
© www.soinside.com 2019 - 2024. All rights reserved.