我正在尝试在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;
}
我从使用Swift
和CLLocationCoordinate2DMake(0,0)
的测试开始,因此问题与设备无关,但它是语言特定于语言>
您不能在 objective-c 中使用(0,0)
,而是使用DBL_MIN
,这是最小的数字,例如:
CLLocationCoordinate2DMake(DBL_MIN, DBL_MIN)