Skip to content

Instantly share code, notes, and snippets.

@GuillaumeJasmin
Last active April 13, 2023 05:02
Show Gist options
  • Save GuillaumeJasmin/70ea310bc4b91e509473 to your computer and use it in GitHub Desktop.
Save GuillaumeJasmin/70ea310bc4b91e509473 to your computer and use it in GitHub Desktop.
iOS GoogleMaps icon marker with image and text
// image
UIImageView *iconView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 50)];
iconView.image = [UIImage imageNamed:@"my-icon-image"];
// text
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 35, 50)];
label.text = @"test";
[iconView addSubview:label];
// grab it
UIGraphicsBeginImageContextWithOptions(label.bounds.size, NO, [[UIScreen mainScreen] scale]);
[iconView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *icon = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(lat, lng);
marker.title = @"my title";
marker.icon = icon;
// mapView is GMSMapView object
marker.map = mapView;
@mmminari
Copy link

you saved my day!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment