在Google地图上为ios添加自定义标记上的文字 [英] Add text on custom marker on google map for ios

查看:381
本文介绍了在Google地图上为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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆