【发布时间】:2011-05-05 15:47:30
【问题描述】:
请帮忙,这个问题已经被问过很多次了,但是人们的建议对我的结果没有影响,我想要的只是要在地图上显示的图钉和蓝色圆圈(准确度),这是我的实现. - 哦,我使用的是 iPhone 设备 - 我不在模拟器中
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
NSLog(@"View for Annotation is called");
if (NSClassFromString(@"MKUserLocation")==[annotation class]) {
return nil;
}
if (annotation == mapView.userLocation) {
return nil;
}
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
annView.pinColor = MKPinAnnotationColorGreen;
UIButton * btn = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
annView.rightCalloutAccessoryView = btn;
annView.animatesDrop=TRUE;
annView.canShowCallout = YES;
annView.calloutOffset = CGPointMake(-5, 5);
pinDropped = TRUE;
return annView;
}
提前欢呼……该死的东西
【问题讨论】:
-
您是否将 mapView.showsUserLocation 设置为 YES?第二个
if没有意义,因为它只是检查注解是否与自身相同。 -
yes 设置所有需要设置的内容,删除第二个 if 语句.. 干杯
-
正在显示什么?你得到别针了吗?还是你得到蓝点和圆圈?或者两者都不是?在不知道实际得到什么的情况下很难进行调试。
-
如果我检查注释是否为 kindOfClass MKUserLocation,我只会得到蓝色圆圈,如果我忽略检查并直接创建一个 MKPinAnnotationView 对象 - 我得到了 pin,抱歉 - 应该这样做更清晰
-
只是为了确认:您会在控制台上看到“调用注释视图”消息,对吧?您能显示将引脚添加到地图的代码的 addAnnotation 部分吗?上面的代码应该可以工作,但您只需要其中一个 if 语句。
标签: iphone mapkit core-location