Search code examples
iosgoogle-maps-sdk-ios

GMSMarker not showing in 1.3


I updated my app to use Google Maps iOS SDK 1.3. Everything seems to work except for the GMSMarkers. They either don't appear or appear with the wrong image. They still respond to touches and can be moved, but are otherwise invisible or corrupt.

Here is the code for adding GMSMarkers:

playerAnnotation = [[CustomPlayerAnnotation markerWithPosition:coord] retain];
[playerAnnotation setType:ANNOTATION_PLAYER];
[playerAnnotation setIcon:[UIImage imageNamed:@"Icon-72.png"]];
[playerAnnotation setGroundAnchor:ccp(.5f, .5f)];
[playerAnnotation setAnimated:NO];
[playerAnnotation setTappable:YES];
[playerAnnotation setTitle:@"Player"];
[playerAnnotation setMap:gameMapView];

GMSMarker* test = [[GMSMarker markerWithPosition:gameMapView.myLocation.coordinate] retain];
[test setIcon:[UIImage imageNamed:@"Icon-72.png"]];
[test setGroundAnchor:ccp(.5f, .5f)];
[test setAnimated:NO];
[test setTappable:YES];
[test setTitle:@"Player"];
[test setMap:gameMapView];

And CustomPlayerAnnotation is simply a GMSMarker with some extra variables:

@interface CustomPlayerAnnotation : GMSMarker
{
    AnnotationType type;
    int tag;
    struct CoordinatePair coordinatePair;
}

Map with CustomPlayerAnnotation and test GMSMarker:

Map with Markers

I do have a large amount of ground overlays, and removing the overlays made a marker reappear, but some still have odd images that aren't showing up properly. It works fine in 1.2.2, but not 1.3.

Does anyone have a workaround for getting Markers working? Anyone else see this behavior in GMSMarkers?

Other Details: The app is using cocos2d 2.0, the director is stopped before loading the map and the GMSMapView is added as follows:

UIWindow* window = [(ProjectFusionAppDelegate*)[[UIApplication sharedApplication] delegate] window];
[[[window subviews] objectAtIndex:0] addSubview:gameMapView];

Solution

  • It looks like there is a bug on Google's side. I just stopped using my CustomPlayerAnnotation or GMSMarker, and used a GMSGroundOverlay instead. That showed up on the map. Then instead of using the type, tag, and coordinatePair I built into CustomPlayerAnnotation, I just relied on the title.

    playerAnnotation = [[GMSGroundOverlay groundOverlayWithPosition:coord icon:[UIImage imageNamed:@"Down1.png"]] retain];
    [playerAnnotation setZoomLevel:zoomLevel];
    [playerAnnotation setAnchor:ccp(.5f, 1)];
    [playerAnnotation setTitle:@"Player"];
    [playerAnnotation setMap:gameMapView];
    

    Side note: notice that I had to setAnchor:ccp(.5f, 1). When it was set to (.5f, .5f) the playerAnnotation overlay would cut off the bottom of the overlay when overlapping other GMSGroundOverlays. Changing the Anchor fixed the z drawing. It looks like 1.4 that just came out may have z-ordering fixed, but 1.4 broke something else on mine so I'll stick with 1.3.1 for now.