iosanimationannotationsapple-watchwkinterfacegroup

Animated annotation on WKInterfaceMap Watchkit


Is there anyway to have an animated annotation for WKInterfaceMap of Watchkit?

I have 35 images to form the animation. Currently I am using a NSTimer which calls

-(void)addAnnotation:(CLLocationCoordinate2D)location withImageNamed:(NSString *)name centerOffset:(CGPoint)offset

method with a different image names but the result is not efficient and the animation is not smooth as everytime it has to first remove the previous annotation and add a new one.

Any comment/suggestion is greatly appreciated.


Solution

  • I think this can not be achieved using WKInterfaceMap but it can be achieved using WKInterfaceImage. I have not implemented all steps but flow can be,

    Generate snapshot of Map with selected lat-long in centre as UIImage using MKMapSnapshotter,

    MKMapSnapshotOptions * snapOptions= [[MKMapSnapshotOptions alloc] init];
    CLLocation * Location = [[CLLocation alloc] initWithLatitude:23.0300 longitude:72.5800];
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(Location.coordinate, 300, 300);
    snapOptions.region = region;
    snapOptions.size = CGSizeMake(300, 300);
    snapOptions.scale = [[UIScreen mainScreen] scale];
    
    MKMapSnapshotter *mapSnapShot = [[MKMapSnapshotter alloc] initWithOptions:snapOptions];
    [mapSnapShot startWithCompletionHandler:^(MKMapSnapshot *snapshot, NSError *error) {
        if (error) {
            NSLog(@"[Error] %@", error);
            return;
        }
    
        UIImage *image = snapshot.image;//map image
        NSLog(@"%@",image);
        [self.mapImage setImage:image];
    }];