iPad Mapkit - Change title of "Current Location" -


in map view, i'm showing current user location. on click on pin showing "current location". want change "my current location". how can change it. want change current user location pin color in timer. thing every 1 second should change color between green, purple , red. possible it?

i'm using map kit's show default location , manipulating annotation pin color below:

- (mkannotationview *)mapview:(mkmapview *)map viewforannotation:(id <mkannotation>)annotation{ static nsstring *annotationviewid = @"annotationviewid"; solarannotationview* annotationview = (solarannotationview*)[map dequeuereusableannotationviewwithidentifier:annotationviewid]; if(annotationview == nil) {     if([self cllocationcoordinate2dequals:mapview.userlocation.location.coordinate withsecondcoordinate:[annotation coordinate]]) //show current location green pin     {         annotationview = [[solarannotationview alloc] initwithannotation:annotation];         annotationview.delegate = self;         [annotationview setpincolor:mkpinannotationcolorgreen];     }     else     {         annotationview = [[solarannotationview alloc] initwithannotation:annotation];         annotationview.delegate = self;     } }     return annotationview; 

}

- (bool) cllocationcoordinate2dequals:(const cllocationcoordinate2d)lhs withsecondcoordinate:(const cllocationcoordinate2d) rhs{ const cllocationdegrees delta = 0.001; return fabs(lhs.latitude - rhs.latitude) <= delta && fabs(lhs.longitude - rhs.longitude) <= delta; 

}

if let map view show default annotation view user location (blue dot), simpler implement (and nice blue dot cool animated zooming circle).

if must show user location using pin image instead of blue dot, more work needed.

first, simple way using blue dot:

- (mkannotationview *)mapview:(mkmapview *)map viewforannotation:(id <mkannotation>)annotation{     if ([annotation iskindofclass:[mkuserlocation class]])     {         ((mkuserlocation *)annotation).title = @"my current location";         return nil;  //return nil use default blue dot view     }      //your existing code viewforannotation here (with corrections)...     static nsstring *annotationviewid = @"annotationviewid";     solarannotationview* annotationview = (solarannotationview*)[map dequeuereusableannotationviewwithidentifier:annotationviewid];     if(annotationview == nil)     {         {             annotationview = [[[solarannotationview alloc] initwithannotation:annotation] autorelease];             //added autorelease above avoid memory leak             annotationview.delegate = self;         }     }      //update annotation in view in case re-using view     annotationview.annotation = annotation;      return annotationview; } 


if want use custom annotation view user location instead, should put pin color changing code in custom view. 1 way periodically change color using performselector:withobject:afterdelay:. in solarannotationview.m, add these 2 methods:

-(void)startchangingpincolor {     switch (self.pincolor) {         case mkpinannotationcolorred:             self.pincolor = mkpinannotationcolorgreen;             break;         case mkpinannotationcolorgreen:             self.pincolor = mkpinannotationcolorpurple;             break;         default:             self.pincolor = mkpinannotationcolorred;             break;     }     [self performselector:@selector(startchangingpincolor) withobject:nil afterdelay:1.0]; }  -(void)stopchangingpincolor {     [nsobject cancelpreviousperformrequestswithtarget:self]; } 

also add method headers solarannotationview.h file.

then change viewforannotation method this:

- (mkannotationview *)mapview:(mkmapview *)map viewforannotation:(id <mkannotation>)annotation{     static nsstring *annotationviewid = @"annotationviewid";     solarannotationview* annotationview = (solarannotationview*)[map dequeuereusableannotationviewwithidentifier:annotationviewid];     if(annotationview == nil)     {         {             annotationview = [[[solarannotationview alloc] initwithannotation:annotation] autorelease];             annotationview.delegate = self;         }     }      //update annotation in view in case re-using view...     annotationview.annotation = annotation;      //stop pin color changing in case re-using view has on     //and annotation not user location...     [annotationview stopchangingpincolor];      if([self cllocationcoordinate2dequals:mapview.userlocation.location.coordinate withsecondcoordinate:[annotation coordinate]]) //show current location green pin     {         [annotationview setpincolor:mkpinannotationcolorgreen];         annotationview.canshowcallout = yes;         ((mkpointannotation *)annotation).title = @"my current location";         [annotationview startchangingpincolor];     }      return annotationview; } 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -