Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to label map markers in Google maps ios

I have a few markers on the map and they each represent a path with a different theme. I want the user to be able to see each of the themes before selecting a marker so I was planning on adding a simple text label above each of them. This doesn't seem to be an embedded function in google maps for ios. Is there any way around this?

like image 501
CSStudent Avatar asked Apr 04 '13 19:04

CSStudent


1 Answers

Set up a UILabel, set it up, render it to a UIImage and set that as the marker's icon.

//setup label
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 20)];
label.text = @"test";
label.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.5];

//grab it
UIGraphicsBeginImageContextWithOptions(label.bounds.size, NO, [[UIScreen mainScreen] scale]);
[label.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * icon = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

//prepare options
GMSMarkerOptions *options = [GMSMarkerOptions options];
options.position = CLLocationCoordinate2DMake(latitude, longitude);
options.title = [NSString stringWithFormat:@"#%d", count_];
options.icon = icon;
like image 152
Daij-Djan Avatar answered Nov 14 '22 16:11

Daij-Djan