2011-03-23 73 views
0

我有一个tableview的部分和第四部分,我已经插入mapview.Now我想显示当前的纬度和经度点击pin.I有经度和纬度。 Pin出现在mapview上,但是当我点击它时,我没有得到任何东西。我写的代码在下面。可以有人告诉我,这里有什么问题?任何示例代码或教程?如何在mapview中显示pin注释?

//这是文件,以获得位置坐标

#import "VolunteerDetailAnnotation.h" 

@implementation VolunteerDetailAnnotation 
@synthesize title; 
@synthesize subtitle; 
@synthesize coordinate; 

/*-(id)init 
{ 
    self=[super init]; 
    if(!self) 
    { 
     return nil; 
    } 
    self.title=nil; 
    self.subtitle=nil; 
    return self; 
}*/ 

-(NSString *)gettitle 
{ 
    return title; 

} 
-(NSString *)getsubtitle 
{ 
    return subtitle; 
} 
-(id)initWithCoordinate:(CLLocationCoordinate2D)inCoord{ 
    self = [self init]; 
    self.coordinate = inCoord; 
    return self; 
} 


- (void)dealloc 
{ 
    self.title=nil; 
    self.subtitle=nil; 
    [super dealloc]; 
} 
@end 

在地图插入

if(index.section==3) 
{ 
      mapView=[[MKMapView alloc] initWithFrame:frame22]; 
      mapView.mapType=MKMapTypeStandard; 
      CLLocationCoordinate2D location = mapView.userLocation.coordinate; 
      MKCoordinateSpan span; 

      MKCoordinateRegion region; 

      location.latitude = [[aVolunteer latitude] floatValue]; 
      location.longitude = [[aVolunteer longitude] floatValue]; 
      mapView.scrollEnabled=YES; 
      span.latitudeDelta = 0.05; 
      span.longitudeDelta = 0.05; 
      mapView.showsUserLocation=YES; 
      region.span = span; 
      region.center = location; 
      VolunteerDetailAnnotation *placemark=[[VolunteerDetailAnnotation alloc] initWithCoordinate:location]; 
      [email protected]"Current Location"; 
      placemark.subtitle=[NSString stringWithFormat:@"%@: %@",aVolunteer.latitude,aVolunteer.longitude] ; 
      [mapView addAnnotation:placemark]; 
      [mapView setRegion:region animated:YES]; 
      [mapView regionThatFits:region]; 
      [cell1 addSubview:mapView]; 
} 

感谢文件!

+0

检查了这一点...
参考网址:http://www.raywenderlich.com/2847/introduction-to-mapkit-on-ios-tutorial
希望这有助于... – SNR 2011-03-23 12:19:52

回答

0

您是否将标注设置为正确?

MKPinAnnotationView *annotationView = nil; 
---init of view etc.. 
annotationView.canShowCallout = YES;