ios - User location is showing like annotation -
i have multiple annotation in mapview
, listed in 3 different arrays. i've used - (mkannotationview *)mapview:(mkmapview *)mapview viewforannotation:(id<mkannotation>)annotation
method change te callout of annotation.
the weird thing userlocation changing customised annotation. why that, , problem?
how listed annotations:
myann = [[annotations alloc]init]; location.latitude = 52.338847; location.longitude = 4.937482; myann.coordinate = location; myann.title = @"afvalpunt"; myann.subtitle = @"rozenburglaan 1"; [category3 addobject:myann]; [self.locationarrays addobject:category3]; self.currentannotation = 0; [self.mymapview addannotations:[self.locationarrays objectatindex:0]];
how method set up:
- (mkannotationview *)mapview:(mkmapview *)mapview viewforannotation:(id<mkannotation>)annotation { mkannotationview *annotationview = [mapview dequeuereusableannotationviewwithidentifier:@"mapan"]; if (!annotationview) { annotationview = [[mkpinannotationview alloc] initwithannotation:annotation reuseidentifier:@"mapan"]; annotationview.canshowcallout = yes; //blauw navigatie auto... uiimageview *carview = [[uiimageview alloc] initwithimage:[uiimage imagenamed:@"driving"]]; uibutton *blueview = [[uibutton alloc] initwithframe:cgrectmake(0, 0, 44, 44+30)]; blueview.backgroundcolor = [uicolor colorwithred:0 green:0.5 blue:1 alpha:1]; carview.frame = cgrectmake(11, 14, carview.image.size.width, carview.image.size.height); [blueview addtarget:self action:@selector(carclicked) forcontrolevents:uicontroleventtouchupinside]; [blueview addsubview:carview]; annotationview.leftcalloutaccessoryview = blueview; } return annotationview; }
try code.
- (mkannotationview *)mapview:(mkmapview *)mapview viewforannotation:(id <mkannotation>)annotation { if (annotation == mapview.userlocation) return nil; ...
we return nil if annotation userlocation let mapview display blue dot & circle animation. in order show our custom annotation userlocation remove line return nil;
, customization there.
- (mkannotationview *)mapview:(mkmapview *)mapview viewforannotation:(id <mkannotation>)annotation { static nsstring* annotationidentifier = @"annotation"; mkpinannotationview *pinview = (mkpinannotationview *)[mapview dequeuereusableannotationviewwithidentifier:annotationidentifier]; if (!pinview) { mkpinannotationview *custompinview = [[[mkpinannotationview alloc] initwithannotation:annotation reuseidentifier:annotationidentifier] autorelease]; if (annotation == mapview.userlocation) { custompinview.image = [uiimage imagenamed:@"mycarimage.png"]; } else { custompinview.image = [uiimage imagenamed:@"mysomeotherimage.png"]; custompinview.animatesdrop = no; custompinview.canshowcallout = yes; return custompinview; } else { pinview.annotation = annotation; } return pinview; }
hope code useful you.
Comments
Post a Comment