我正在尝试在地图上有按钮的iPhone应用程序,我该怎么做?我已经实施了MKMapView
并设置了longitude/latitude
并将其集中在我想要的位置。
答案 0 :(得分:6)
你没有详细说明你的问题,所以我想你想要,
Use MKUserTrackingBarButtonItem
- (void)viewDidLoad
{
[super viewDidLoad];
MKUserTrackingBarButtonItem *buttonItem = [[MKUserTrackingBarButtonItem alloc] initWithMapView:self.map];
self.navigationItem.rightBarButtonItem = buttonItem;
}
AMKUserTrackingBarButtonItem
object是一个专门的栏按钮项,允许用户切换用户跟踪模式。例如,当用户点击按钮时,地图视图在跟踪具有和不具有标题的用户之间切换。如果在其他位置设置,该按钮还会反映当前用户跟踪模式。此栏按钮项目与单个地图视图相关联。
答案 1 :(得分:1)
试试吧......
- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *pinAnnotation = nil;
if(annotation != myMapView.userLocation)
{
static NSString *defaultPinID = @"myPin";
pinAnnotation.pinColor = MKPinAnnotationColorRed;
pinAnnotation = (MKPinAnnotationView *)[myMapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinAnnotation == nil )
pinAnnotation = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
pinAnnotation.canShowCallout = YES;
infoButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 25, 25)];
[infoButton setBackgroundImage:[UIImage imageNamed:@"arrow_go_map.png"] forState:UIControlStateNormal];
pinAnnotation.rightCalloutAccessoryView = infoButton;
[infoButton addTarget:self action:@selector(detailBtnClk:) forControlEvents:UIControlEventTouchUpInside];
}
return pinAnnotation;
}
希望我帮助