i have problem.
have mapview, , have many annotations in mapview.
how know indexpath
select annotation.
find function didselectannotationview
don't know how use it.
this code:
bool firstlocationreceived; -(void)locationmanager:(cllocationmanager *)manager didupdatelocations:(nsarray<cllocation *> *)locations { cllocation *currentlocation = locations.lastobject; //current location if(firstlocationreceived == no) { mkcoordinateregion region = _shopmapview.region; region.center = currentlocation.coordinate; region.span.latitudedelta = 0.05; region.span.longitudedelta = 0.05; [_restaurantmapview setregion:region animated:true]; //add annotation (int = 0; < self.items.count ; i++) { mkpointannotation *annotation = [mkpointannotation new]; nsdictionary *item = self.items[i]; cllocationdegrees latitude = [item[@"latitude"] doublevalue]; cllocationdegrees longitude = [item[@"longitude"] doublevalue]; annotation.coordinate = cllocationcoordinate2dmake(latitude, longitude); annotation.title = item[@"name"]; annotation.subtitle = item[@"address"]; [_shopmapview addannotation:annotation]; firstlocationreceived == yes; } } } -(mkannotationview*)mapview:(mkmapview *)mapview viewforannotation:(id<mkannotation>)annotation { if (annotation == mapview.userlocation) { return nil; } nsstring *identifier = @"shop"; mkannotationview *result = [mapview dequeuereusableannotationviewwithidentifier:identifier]; if(result ==nil) { result = [[mkannotationview alloc]initwithannotation:annotation reuseidentifier:identifier]; } else { result.annotation = annotation; } result.canshowcallout = true; uiimage *annotationviewimage = [uiimage imagenamed:@"point.png"]; result.image = annotationviewimage; result.leftcalloutaccessoryview = [[uiimageview alloc]initwithimage:annotationviewimage]; uibutton *button = [uibutton buttonwithtype:uibuttontypedetaildisclosure]; [button addtarget:self action:@selector(buttontapped:) forcontrolevents:uicontroleventtouchupinside]; result.rightcalloutaccessoryview = button; return result; }
thanks!
you can selected annotation index way,
-(void)mapview:(mkmapview *)mapview didselectannotationview:(mkannotationview *)view{ mkpointannotation * annotation = [[mkpointannotation alloc]init]; annotation = view.annotation; nsstring * selectedtitle = [nsstring stringwithformat:@"%@",annotation.title]; nsinteger index = [[self.items valueforkey:@"name"] indexofobject:selectedtitle]; //considering self.items nsdictionary consist of annotation names. nslog(@"you selected index: %ld",(long)index); }
get
annotation title
of selected annotation point , lets find it's index in our array of names.
Comments
Post a Comment