8

I have loaded the custom annotation image for user current location.I am updating the current user location after every 1 sec in background.

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[self performSelectorOnMainThread:@selector(tempupdate) withObject:nil waitUntilDone:NO];
[pool release];

-(void)tempupdate
{
    NSLog(@"callToLocationManager");
    mylocationManager = [[CLLocationManager alloc]init];
    NSLog(@"locationManagerM = %@",mylocationManager);
    mylocationManager.delegate = self;
    mylocationManager.desiredAccuracy = kCLLocationAccuracyBest;
    mylocationManager.distanceFilter = 500;
    [mylocationManager startUpdatingLocation];
}

After updating the current latutude and longitude i am refreshing the map using following code

MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=0.002;
span.longitudeDelta=0.002;
CLLocationCoordinate2D location;
location.latitude=[lat doubleValue];
location.longitude=[longt doubleValue];
region.span=span;
region.center=location;
addAnnotation=[[AddressAnnotation alloc]initWithCoordinate:location];
addAnnotation.mTitle=@"You are here";
[self.mapView removeAnnotations:self.mapView.annotations];
[self.mapView addAnnotation:addAnnotation];
[self.mapView setRegion:region animated:TRUE];
[self.mapView regionThatFits:region];

But every time custom annotation image blinks before adding to the map.How to avoid this flicker effect?

Martin
  • 11,881
  • 6
  • 64
  • 110
Akshay Aher
  • 2,525
  • 2
  • 18
  • 33

3 Answers3

3

I haven't tested this yet, but based on a quick glance at your code, I would guess the issue lies in your removal of the annotation and then adding a new one.

Have you tried just editing the already attached annotation's properties?

NSArray* curAnnotations = [mapView annotations];
AddressAnnotation* aa = [curAnnotations lastObject]; // I am assuming you only have 1 annotation
aa.mTitle = @"You are here"; // or don't do this if it never changes
[aa setCoordinate:location];

Note: Apple Docs specifically call out the 'setCoordinate' method as something that should be used to support dragging or frequent updates.

MobileVet
  • 2,958
  • 2
  • 26
  • 42
  • i know issue lies in removing and adding annotations on map-view but is there any other way to do this?can you please tell me in details what should i do? – Akshay Aher Mar 19 '12 at 06:43
  • Hey thanks for the reply.but its not working.its still gives me jumping like effect. – Akshay Aher Mar 27 '12 at 11:48
  • Sorry to hear that, wish I had more experience with that call to help. Cheers and good luck. – MobileVet Mar 27 '12 at 22:17
1

you mustn't remove annotation from map. Instead change the annotation coordinate in the UIView beginAnimations-commitAnimations block;

It will look something like this:

[UIView beginAnimations:@"yourAnimationName" context:nil];
[UIView setAnimationDuration:1.0];
[yourAnnotation setCoordinate:yourNewCoordinate];
[UIView commitAnimations];

It will move smoothly the annotation.

BR, Marcin Szulc

Marcin Szulc
  • 141
  • 2
  • 13
0
//SWIFT 3
UIView.beginAnimations("yourname", context: nil)
UIView.setAnimationDuration(1.0)
yourpin.coordinate = MKCoordinateForMapPoint(mycoordinate)
UIView.commitAnimations()
rara
  • 470
  • 4
  • 8