简体   繁体   中英

Draggable pin on mapview

Hi am trying to create a draggable pin , but it not moving when i try to move the pin only the map moves around and the pin stays at the smae position what mi doing wrong.

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{

    MKPinAnnotationView *test=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"parkingloc"];
    if([annotation title]==@"Parked Location")
    {
//      
        [test setUserInteractionEnabled:YES];
        [test setCanShowCallout:YES];
        [test setDraggable:YES];
        return test;    
    }
    [
    return test;    
}

also my custom annonation class is like these

- (NSString *)subtitle{
    return @"Put some text here";
}
- (NSString *)title{
    return @"Parked Location";
}

-(id)initWithCoordinate:(CLLocationCoordinate2D) c{

    coordinate=c;
    NSLog(@"%f,%f",c.latitude,c.longitude);
    return self;
}
- (void)setCoordinate:(CLLocationCoordinate2D)newCoordinate
{
    coordinate=newCoordinate;
}

but its not working why...?

This is old but incase anyone is interested in the future:

If no |title| is set for the MKPinAnnotationView, dragging won't work either.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM