-
-
Save jechague/978590f05b2229908daab09dc1898932 to your computer and use it in GitHub Desktop.
iOS GoogleMaps icon marker with image and text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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