ios - Custom one annotation on MKMapView -


i fill map mkplacemark, specific address, these mark correspond meeting.

i'm trying custom 1 placemark corresponds next meeting.

here code:

// function add pin corresponding meeting. - (void) addallpins {     _mymap.delegate = self;      // key of meeting     nsarray* allkey = [[vsdataprovider sharedmanager].startevents allkeys];      (nsdate *date in allkey) {         (ffevent *event in [[vsdataprovider sharedmanager].startevents objectforkey:date]) {              // retrieve clgeocoder latitude , longitude address of event             nsstring *localisation = [nsstring stringwithformat:@"%@ %@ %@ %@",event.street,event.zipcode,event.city,event.country];              clgeocoder *geocoder = [[clgeocoder alloc] init];             [geocoder geocodeaddressstring:localisation completionhandler:^(nsarray *placemarks, nserror *error) {                 if (placemarks && placemarks.count > 0) {                     clplacemark *topresult = [placemarks objectatindex:0];                     mkplacemark *place = [[mkplacemark alloc] initwithplacemark:topresult];                     [arraywithalllocation addobject:place];                     [self addpinwithtitle:event.street andcoordinatelongitude:place.coordinate.longitude andcoordinatelatitude:place.coordinate.latitude];                 }                  [self getcoordinatenexevent:^{                     (mkplacemark *mark in arraywithalllocation) {                         if (mark.coordinate.latitude ==  _coordinatenextevent.latitude && mark.coordinate.longitude == _coordinatenextevent.longitude) {                             mkannotationview *test = [[mkannotationview alloc]initwithannotation:mark reuseidentifier:@"nextevent"];                             test.annotation = mark;                             test.image = [uiimage imagenamed:@"meeting.png"];                             [_mymap addannotation:test.annotation];                          }                     }                 }];             }];         }     } }  // retrieve coordinate next meeting - (void) getcoordinatenexevent :(void (^)(void))afterall {     ffevent *event = [vsdataprovider sharedmanager].nextevent;     clgeocoder *geocoder = [[clgeocoder alloc]init];     nsstring *localisation = [nsstring stringwithformat:@"%@ %@ %@ %@",event.street,event.zipcode,event.city,event.country];     [geocoder geocodeaddressstring:localisation completionhandler:^(nsarray *placemarks, nserror *error) {          if (placemarks && placemarks.count > 0) {             clplacemark *topresult = [placemarks objectatindex:0];             placemark = [[mkplacemark alloc] initwithplacemark:topresult];             _coordinatenextevent.latitude = placemark.coordinate.latitude;             _coordinatenextevent.longitude = placemark.coordinate.longitude;         }          afterall();     }]; }  // method add pin title , coordinate - (void) addpinwithtitle : (nsstring*)title andcoordinatelongitude : (double)coordinatelongitude andcoordinatelatitude : (double)coordinatelatitue {     mkpointannotation *mappin = [[mkpointannotation alloc]init];     cllocationcoordinate2d coordinate = cllocationcoordinate2dmake(coordinatelatitue, coordinatelongitude);     mappin.title = title;     mappin.coordinate = coordinate;     [self.mymap addannotation:mappin]; }  - (void) mapview:(mkmapview *)mapview didupdateuserlocation:(mkuserlocation *)userlocation {         mkcoordinateregion region;     mkcoordinatespan span;      span.latitudedelta = 0.5;     span.longitudedelta = 0.5;      cllocationcoordinate2d location;     location.latitude = userlocation.coordinate.latitude;     location.longitude = userlocation.coordinate.longitude;      region.span = span;     region.center = location;      [_mymap setregion:region animated:yes]; } 

when use

- (mkannotationview*) mapview:(mkmapview *)mapview viewforannotation:(id<mkannotation>)annotation {      __block mkannotationview *annotationwithnextevent;      annotationwithnextevent = (mkannotationview*) [_mymap dequeuereusableannotationviewwithidentifier:@"nexteventannotation"];      if (!annotationwithnextevent) {          annotationwithnextevent = [[mkannotationview alloc] initwithannotation:placemark reuseidentifier:@"nexteventannotation"];     }     annotationwithnextevent.image = [uiimage imagenamed:@"meeting.png"];     annotationwithnextevent.annotation = annotation;     return annotationwithnextevent; } 

all annotations image, don't want this.

i hope i'm clear

you should create subclass following:

@interface meetingpointannotation : mkpointannotation @property (strong, nonatomic) nsstring *customdata; @end 

and check it:

- (mkannotationview *)mapview:(mkmapview *)mapview viewforannotation:(id <mkannotation>)annotation {     if ([annotation iskindofclass:[meetingpointannotation class]]) {         __block mkannotationview *annotationwithnextevent;         annotationwithnextevent = (mkannotationview*) [_mymap dequeuereusableannotationviewwithidentifier:@"nexteventannotation"];          if (!annotationwithnextevent) {             annotationwithnextevent = [[mkannotationview alloc] initwithannotation:placemark reuseidentifier:@"nexteventannotation"];         }          annotationwithnextevent.image = [uiimage imagenamed:@"meeting.png"];         annotationwithnextevent.annotation = annotation;         return annotationwithnextevent;     }     return nil; } 

this customize type of annotation

also code may have issues clgeocoder because may potentially use lot. read documentation:

applications should conscious of how use geocoding. geocoding requests rate-limited each app, making many requests in short period of time may cause of requests fail. (when maximum rate exceeded, geocoder returns error object value kclerrornetwork associated completion handler.) here rules of thumb using class effectively:

  • send @ 1 geocoding request 1 user action.

  • if user performs multiple actions involve geocoding same location, reuse results initial geocoding request instead of starting individual requests each action.

  • when want update user’s current location automatically (such when user moving), issue new geocoding requests when user has moved significant distance , after reasonable amount of time has passed. example, in typical situation, should not send more 1 geocoding request per minute.

  • do not start geocoding request @ time when user not see results immediately. example, not start request if application inactive or in background.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -