Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment