ios - Hiding the pins/markers from the map view through method in iPhone -
ios - Hiding the pins/markers from the map view through method in iPhone -
in viewdidload:
method show different locations of number of vehicles have used pins/markers/annotations.
what want know if user selects 1 vehicle how can hide other pins/markers.
is possible?
how that?
yes, possible. first need add together observer each annotationview observe when user selects annotation. first must add:
static nsstring * const gmap_annotation_selected = @"gmapannotationselected";
to top of implementation (right below @implementation). must add together observer each annotationview. done by:
-(mkannotationview *)mapview:(mkmapview *)localmapview viewforannotation:(id<mkannotation>)annotation //create custom annotation called annotationview [annotationview addobserver:self forkeypath:@"selected" options:nskeyvalueobservingoptionnew context:(void*)("gmapannotationselected")]; homecoming annotationview;
then add together next function same file gets called when annotationview selected:
- (void) observevalueforkeypath:(nsstring *)keypath ofobject:(id)object change:(nsdictionary *)change context:(void *)localcontext { char *actioncharstr = (char*)localcontext; nsstring *action = [nsstring stringwithcstring:actioncharstr encoding:nsstringencodingconversionallowlossy]; if ([action isequaltostring:gmap_annotation_selected]) { bool annotationselected = [[change valueforkey:@"new"] boolvalue]; customannotationview *customannotationview; if (annotationselected) { currentannotationview = (customannotationview*)object; //go through each annotation in [yourmap annotations] , remove map if not equal [currentannotationview annotation] } else { currentannotationview = (customannotationview*)object; //add annotations 1 time annotation no longer selected } }}
for more information, at: how observe annotationview selected mkmapviewdelegate
iphone ios mapkit
Comments
Post a Comment