Can we create flashing red/blue circle around user location in mapview in iPhone ?

C

Yes we can create with a simple UIView animation & few images.

1) Add the MapView

MKMapView *mapView = [[MKMapView alloc] initWithFrame:yourFrameFrame];

mapView.mapType = MKMapTypeStandard;

mapView.delegate = self;

[mapView setShowsUserLocation:YES];

[self.view addSubview:mapView];

 

2) In viewForAnnotation method
– (MKAnnotationView *)mapView:(MKMapView *)mapview viewForAnnotation: (id <MKAnnotation>)annotation

{

UIImage *anImage = nil;

UIImageView *overlayImage;

if (annotation == mapview.userLocation)

{

MKPinAnnotationView *customPinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@”annotation”] autorelease];

customPinView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@”redLocation.png” ofType:nil]];

customPinView.animatesDrop = NO;

customPinView.canShowCallout = YES;

 

overlayImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@”OverlayImage.png”]];

overlayImage.frame = CGRectMake(0, 0, 15, 15);

overlayImage.center = CGPointMake(customPinView.center.x+7, customPinView.center.y+7);

[customPinView addSubview:overlayImage];

// timer for animation

NSTimer *mapTimer = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(createOverlayAnimation) userInfo:nil repeats:YES];

 

 

return customPinView;

}

}

-(void)createOverlayAnimation

{

overlayImage.transform = CGAffineTransformMakeScale(1,1);

[UIView beginAnimations:nil context:NULL];

[UIView setAnimationDuration:1.0];

overlayImage.transform = CGAffineTransformMakeScale(5,5);

overlayImage.alpha = 1.0;

[UIView commitAnimations];

}

About the author

surjit.joshi
By surjit.joshi

Category