你好,我得到了这个方法:
-(void)adresseZeigen
{
NSLog(@"%s",__PRETTY_FUNCTION__);
selectedAnnotation = [[MKPointAnnotation alloc]init];
selectedAnnotation.title = selectedCompanyName;
selectedAnnotation.subtitle = selectedCompanyAdresse;
selectedAnnotation.coordinate = selectedCompanyPoint;
NSLog(@"selected title: %@",selectedAnnotation.title);
NSLog(@"selected subtitle: %@",selectedAnnotation.subtitle);
NSLog(@"selected latitude is: %f", self.selectedAnnotation.coordinate.latitude );
NSLog(@"selected longitude is: %f", self.selectedAnnotation.coordinate.longitude );
[mapView addAnnotation:selectedAnnotation];
MKCoordinateRegion selectedRegion;
selectedRegion.center = selectedCompanyPoint;
selectedRegion.span.longitudeDelta = 0.01;
selectedRegion.span.latitudeDelta = 0.01;
[mapView setRegion:selectedRegion animated:YES];
}它实际上应该在我的mapview中给我一个注释。
我的日志输出是:
-[SecondViewController adresseZeigen]
selected title: Company 2
selected subtitle: Company 2 Adresse
selected latitude is: 48.620000
selected longitude is: 9.460000但不知何故,我在地图上得不到注解。
有人能帮帮我吗?
发布于 2013-05-14 16:24:43
仅此一项并不能为您提供地图上的任何实际注释视图。为了在地图中拥有注释视图,您需要为视图控制器声明MKMapViewDelegate,将其声明为您的mapview委托并实现该方法:
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation这是为地图视图实际生成注释视图的方法。在您的例子中,您可能希望为MKPointAnnotation使用MKPinAnnotationView!
您可以查看协议参考here。
EDIT:该方法的示例实现(假设您的所有MKPointAnnotations都有相同的用途)可以是:
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
static NSString *reuseId = @"MyReuseID";
MKPinAnnotationView * view = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseId];
if (!view) {
view = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseId];
//custom setup of your view, such as
//view.canShowCallout = YES;
}
return view;
}https://stackoverflow.com/questions/16532896
复制相似问题