Do marker animations exist on GoogleMaps SDK for iOS?
Asked Answered
M

4

11

Is it possible to move/rotate GMSMarker on GMSMapView with animation?

Moule answered 19/1, 2013 at 13:18 Comment(3)
they exist now! from 1.2 onward BUT I don't see how they work / are supposed to workAtchley
SOME animation.. I guess I read wrong in my excitementAtchley
WORKING ans check on this : https://mcmap.net/q/1019419/-move-gmsmarker-on-google-map-like-uberRubierubiginous
P
7

The addition in 1.2 is that the GMSMarker class has an animated property - I presume you just set it to YES, before adding the marker to the map by settings its map property (I haven't tried it though).

https://developers.google.com/maps/documentation/ios/reference/interface_g_m_s_marker

GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(-33.8683, 151.2086);
marker.title = @"Sydney";
marker.snippet = @"Australia";
marker.animated = YES;
marker.map = mapView_;

I presume this means that the marker will be animated when it is dropped onto the map - not that you can make a high-speed animated marker like this original question was asking.

Precedent answered 19/4, 2013 at 0:23 Comment(3)
yes, as I said ;) I did read the 'documentation' wrong. you are rightAtchley
Since v1.5 the animated field became appearAnimation.Fortieth
See answer here #15289335Vermicelli
D
1

No I'm afraid they are not as we have no access to the OpenGL context that Google Maps has access to. The best you can do is rotate a marker as a UIImage which requires a redraw or you can move a marker but it will jump unless you do it in very small increments!

I suggest reporting a bug to Google and they may be able to include it

Douglass answered 23/1, 2013 at 8:0 Comment(6)
Unfortunately, rotating image and assigning new one to GMSMarker also doesn't work correctly. If such images generated relatively fast (even not too fast), then behaviour of marker is strange. I see "jumps" to previous states (images), or disappearing of marker, instead of displaying new icon. UIImage rotation is checked and I am sure that it is a problem of GMSMarker. (I tested it without API Key, of course, it can be the reason). So, what I can say, that current version of Google Maps SDK on iOS can be used only for static objects.Moule
Check out our app that just released with moving and rotated markers bit.ly/PFinderDouglass
Looks good. But how often do you update markers of planes? And am I right that you assign new image to the id<GMSMarker> icon property?Moule
They update location every second and the image not so often but you are correct in the method.Douglass
@LeeArmstrong, I looked at your app, do you mind answering: this question. Thanks.Devest
they exist now! from 1.2 onward BUT I don't see how they work / are supposed to workAtchley
E
1

My solution was to subclass the GMSMarker class and add support for PNG sequences using a timer. Here's a rough sketch of the code:

.h:

#import <GoogleMaps/GoogleMaps.h>

@interface AnimatedGMSMarker : GMSMarker

@property (nonatomic, strong) NSString *animationBaseName;

-(void)setAnimation:(NSString *)name forFrames:(NSArray *)frames;

@end

.m

#import "AnimatedGMSMarker.h"

@implementation AnimatedGMSMarker{
    int _currentFrame;
    NSArray *_frameArray;
    NSTimer *_timer;
}

-(void)setAnimation:(NSString *)name forFrames:(NSArray *)frames{
    _frameArray = frames;
    _currentFrame = 0;
    _animationBaseName = name;
    self.icon = [UIImage imageNamed:[NSString stringWithFormat:@"%@%@",_animationBaseName,_frameArray[_currentFrame++]]];
    _timer = [NSTimer scheduledTimerWithTimeInterval:1.0/24.0f
                                                     target:self
                                                   selector:@selector(onRefreshTimer:)
                                                   userInfo:nil
                                                    repeats:YES];
}

-(void)onRefreshTimer:(NSTimer *)timer{
    self.icon = [UIImage imageNamed:[NSString stringWithFormat:@"%@%@",_animationBaseName,_frameArray[_currentFrame++]]];
    if (_currentFrame >= _frameArray.count){
        _currentFrame = 0;
    }
}

@end

And then once you instantiate one, just send it something like this:

[self.myAnimatedMarker setAnimation:@"some_library_name" forFrames:@[@0,@1,@2,@3,@4,@5,@6,@7,@8,@9]];

And make sure your library has a bunch of PNGs of the same size and registration that are named "some_library_name0" "some_library_name1", etc. The frame array treatment allows you to repeat frames without creating new PNGs.

Performance-wise, it's very slow to animate in the simulator but seems pretty performant on the device.

Good luck!

Equator answered 5/5, 2015 at 16:21 Comment(0)
D
0

For now markers only have an option to appear animated.

Recently wrote clusterization lib for Google Maps SDK for iOS with animated collapse/disintegration. And the approach I used was animation through manual position update. If there's a lot markers on screen simultaneously animating it's sloow (even with all the possible calculations in background and results caching), so needs a lot of optimizations and limitations. So for now it's good to think a lot if you really need animations like this with Google Maps SDK for iOS or sometimes, especially on older devices, the optimization you'll have to use will be disabling your custom animations at all.

Dna answered 16/5, 2013 at 7:9 Comment(2)
is the clusterization lib that you have mentioned above, available in public domain? if so , can you please share the linkLavernalaverne
@tony, sorry, I developed it exclusively for my company.Dna

© 2022 - 2024 — McMap. All rights reserved.