地图定位MKMapView怎么样让多个大头针显示在一个屏幕上
展开全部
(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *pinview = nil;
if (annotation != mapView.userLocation) {
static NSString *defaultId = @"目的地";
pinview = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultId];
if (pinview == nil) {
pinview = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultId] autorelease];
pinview.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pinview.pinColor = MKPinAnnotationColorPurple;
pinview.canShowCallout = YES;
pinview.animatesDrop = YES;
pinview.draggable = YES;
pinview.selected = YES;
}
}
else
{
[mapView.userLocation setTitle:@"I'm here"];
}
return pinview;
}
给pinview的pinview.rightCalloutAccessoryView添加一个按钮,实现委托方法
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
增加按钮的点击响应,切换到一个新的视图,来展示完整的信息
{
MKPinAnnotationView *pinview = nil;
if (annotation != mapView.userLocation) {
static NSString *defaultId = @"目的地";
pinview = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultId];
if (pinview == nil) {
pinview = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultId] autorelease];
pinview.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pinview.pinColor = MKPinAnnotationColorPurple;
pinview.canShowCallout = YES;
pinview.animatesDrop = YES;
pinview.draggable = YES;
pinview.selected = YES;
}
}
else
{
[mapView.userLocation setTitle:@"I'm here"];
}
return pinview;
}
给pinview的pinview.rightCalloutAccessoryView添加一个按钮,实现委托方法
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
增加按钮的点击响应,切换到一个新的视图,来展示完整的信息
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询