我的注释(homeMark)没有在mapView中显示。 我在IB中创建了viewController委托
由于某种原因在委托方法中 if([注释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;
}
答案 0 :(得分: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