在Google地图上为ios添加自定义标记上的文字 [英] Add text on custom marker on google map for ios
问题描述
我试图用Textview标记标记。是否有任何可能性在iOS中的谷歌地图上添加标记。
您必须创建一个视图,您必须创建一个imageView(带有标记图像)和Label与您的文本),并截取该视图的截图,并设置为您的GMSMarker图标。
类似于这样:
$ $ $
$
$ G $标记= [GMSMarker新];
UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0,0,60,60)];
UIImageView * pinImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@myPin]];
UILabel * label = [UILabel new];
label.text = @1;
//label.font = ...;
[label sizeToFit];
[view addSubview:pinImageView];
[view addSubview:label];
//i.e。定制视图以获取所需内容
UIImage * markerIcon = [self imageFromView:view];
marker.icon = markerIcon;
marker.map = self.mapView; $ {
}
$ b - (UIImage *)imageFromView:(UIView *)view
{
if([[UIScreen mainScreen] respondsToSelector:@selector(scale)])) {
UIGraphicsBeginImageContextWithOptions(view.frame.size,NO,[[UIScreen mainScreen] scale]);
} else {
UIGraphicsBeginImageContext(view.frame.size);
}
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
返回图片;
}
Am trying to put marker with Textview .Is there any posibility to add text over marker on google map in ios.
You must make a view, where you must create an imageView (with your marker image) and Label (with your text) and take a screenshot of that view, and set as icon to your GMSMarker. Something like this:
- (void)foo
{
GMSMarker *marker = [GMSMarker new];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0,0,60,60)];
UIImageView *pinImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myPin"]];
UILabel *label = [UILabel new];
label.text = @"1";
//label.font = ...;
[label sizeToFit];
[view addSubview:pinImageView];
[view addSubview:label];
//i.e. customize view to get what you need
UIImage *markerIcon = [self imageFromView:view];
marker.icon = markerIcon;
marker.map = self.mapView;
}
- (UIImage *)imageFromView:(UIView *) view
{
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
UIGraphicsBeginImageContextWithOptions(view.frame.size, NO, [[UIScreen mainScreen] scale]);
} else {
UIGraphicsBeginImageContext(view.frame.size);
}
[view.layer renderInContext: UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
这篇关于在Google地图上为ios添加自定义标记上的文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!