如何添加具有一个标题的标注

时间:2013-08-20 07:53:13

标签: iphone ios mkmapview cllocationmanager

我的地图代码:

if (latitude != [NSNull null] && longitude != [NSNull null])
    {
    location.latitude=[latitude doubleValue];
    location.longitude=[longitude doubleValue];
    MyAnnotationView *newannotation=[[MyAnnotationView alloc]initWithTitle:[NSString stringWithFormat:@"Bus-%d",h] latitude:location.latitude longitude:location.longitude];
    [self.myMap addAnnotation:newannotation];
    myMap.mapType=MKMapTypeStandard;
    [myMap setCenterCoordinate:location animated:YES];
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(location,1000,1000);
    [myMap setRegion:region animated:YES];

    }

-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{

location.latitude=newLocation.coordinate.latitude;
location.longitude=newLocation.coordinate.longitude;
MyAnnotationView *newannotation=[[MyAnnotationView alloc]initWithTitle:[NSString stringWithFormat:@"Bus-%d",h] latitude:location.latitude longitude:location.longitude];
[self.myMap addAnnotation:newannotation];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(location,1000, 1000);
[myMap setRegion:region animated:YES];
[myMap setCenterCoordinate:newLocation.coordinate animated:YES];
}

mkannotationview.h

@implementation MyAnnotationView
@synthesize title,coordinate;
-(id)initWithTitle:(NSString *)newTitle latitude:(float)newLatitude longitude:(float)newLongitude
{

    if (self=[super init])

    {
        title=newTitle;
        coordinate.latitude=newLatitude;
        coordinate.longitude=newLongitude;

    }
    return  self;
}

如何添加带有该标题的标注?单击该注释时,它不会弹出。当我点击时,我收到以下线程错误

EXC_BREAKPOINT(code=EXC_1386+BPT,subcode 0.0)

0 个答案:

没有答案