我想在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)