ios - how to show different markerInfoWindow? -
i'm using gms ios. , i'm facing problem can't detect marker did tapped!(custom markerinfowindow)
you can see code custom markerinfowindow :
here i'm creating markers :
-(void)createmarks{ (int l=0 ; l<self.nsmuatablearray.count; l++) { cllocationcoordinate2d pos = cllocationcoordinate2dmake([[[self.nsmuatablearray objectatindex:l] objectforkey:@"lati"] doublevalue],[[[self.nsmuatablearray objectatindex:l] objectforkey:@"longi"] doublevalue]); gmsmarker *marker = [[gmsmarker alloc]init]; marker.position=pos; marker.draggable = no; marker.map = mapview_; }}
here delegate :
-(uiview*)mapview:(gmsmapview *)mapview markerinfowindow:(gmsmarker *)marker{ custominfowindow*infow = [[[nsbundle mainbundle] loadnibnamed:@"infowindow" owner:self options:nil] objectatindex:0]; (l=0; l<self.nsmuatablearray.count; l++) { infow.title.text =[[self.nsmuatablearray objectatindex:l ]objectforkey:@"title"] ; infow.time.text = [[self.nsmuatablearray objectatindex:l ]objectforkey:@"time"] ; } return infow; }
so how can detect object tapped ?
thanks.
ok, createmarks
method correct, thing missing, way identify marker afterwards. add it:
marker.userdata = [self.nsmuatablearray objectatindex:l];
now, on mapview:markerinfowindow:
. loop doesn't make sense. instead, this:
-(uiview*)mapview:(gmsmapview *)mapview markerinfowindow:(gmsmarker *)marker{ custominfowindow*infow = [[[nsbundle mainbundle] loadnibnamed:@"infowindow" owner:self options:nil] objectatindex:0]; nsdictionary * data = (nsdictionary*)marker.userdata; infow.title.text =[data objectforkey:@"title"]; infow.time.text = [data objectforkey:@"time"]; return infow; }
the problem didn't understand how method work. called every time user taps on marker. asking what view should show when marker tapped
. , running on markers , overwriting data on same view.
now, gmsmarker
's have cool property userdata
can store whatever like. useful identify marker later.
Comments
Post a Comment