2

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.

Midhun MP
  • 103,496
  • 31
  • 153
  • 200
amistres
  • 63
  • 1
  • 7
  • In WKInterfaceMap framework reference, it is mentioned, 'Maps can display no more than five annotations at a time.' - https://developer.apple.com/library/ios/documentation/WatchKit/Reference/WKInterfaceMap_class/index.html#//apple_ref/occ/cl/WKInterfaceMap – Dhaval Panchal Jun 08 '15 at 04:25
  • Thanks for your comment. I did not mean that, I would like to have 35 images on the map. I would like to have an animated annotation and the animation in Apple Watch apps seem to be doable only using a group of images. So simply, how is it possible to have an animated pin on the map on the watch. – amistres Jun 09 '15 at 21:11
  • It can be achieved with WKInterfaceImage, check updated answer. – Dhaval Panchal Jun 11 '15 at 06:17

1 Answers1

0

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];
}];
  • We already have Annotation image in resource So dynamically create merged images of annotation image to map snapshot image. If you want to add animation from top then you need to render annotation image from point (150,0) to (150,150) on map image. If you are generating 15 images for animation then you need set for loop with 15 limit and each time increase Y of annotation image to 150/15 = 10. Keep track of these merged images in NSMutableArray. You may consider this answer for rendering images.

  • Use these dynamically generated NSMutableArray of images and set to Animation for WKInterfaceImage to achieve map annotation.

Community
  • 1
  • 1
Dhaval Panchal
  • 2,529
  • 1
  • 25
  • 36
  • Thanks for your reply. I did not mean that, I would like to have 35 images on the map. I would like to have an animated annotation and the animation in Apple Watch apps seem to be doable only using a group of images. So simply, how is it possible to have an animated pin on the map on the watch. – amistres Jun 09 '15 at 21:12
  • MKMapSnapshotter is not available in Apple watch yet. – Parth Adroja Jan 15 '18 at 13:27