将标注添加到GMSMapview的自定义infoMarkerWindow实现中 [英] Add callouts to custom infoMarkerWindow implementations for GMSMapview

查看:69
本文介绍了将标注添加到GMSMapview的自定义infoMarkerWindow实现中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google IOS SDK,并已实现

I am using Google IOS SDK and have implemented

- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker

实施自定义视图.当我显示此视图时,它不会像Google地图视图通常为其自己的标记那样添加标注.任何人都可以让我知道如何添加此标注,例如指向指向此自定义makerInfoWindow标记的指针?

to implement a custom view. When I show this view, it does not add a callout as Google map view normally does for its own markers. Can anyone please let me know how it would be possible to add this callout like pointer pointing towards the marker for this custom makerInfoWindow ?

推荐答案

此处是操作方法.

- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker{
    int popupWidth = 300;
    int contentWidth = 280;
    int contentHeight = 140;
    int contentPad = 10;
    int popupHeight = 200;
    int popupBottomPadding = 16;
    int popupContentHeight = contentHeight - popupBottomPadding;
    int buttonHeight = 30;
    int anchorSize = 20;
    CLLocationCoordinate2D anchor = marker.position;
    CGPoint point = [mapView.projection pointForCoordinate:anchor];


    UIView *outerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, popupWidth, popupHeight)];
    float offSet = anchorSize * M_SQRT2;
    CGAffineTransform rotateBy45Degrees = CGAffineTransformMakeRotation(M_PI_4); //rotate by 45 degrees
    UIView *callOut = [[UIView alloc] initWithFrame:CGRectMake((popupWidth - offSet)/2.0, popupHeight - offSet, anchorSize, anchorSize)];
    callOut.transform = rotateBy45Degrees;
    callOut.backgroundColor = [UIColor blackColor];
    [outerView addSubview:callOut];

    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, popupWidth, 190)];
    [view setBackgroundColor:[UIColor whiteColor]];

    view.layer.cornerRadius = 5;
    view.layer.masksToBounds = YES;

    view.layer.borderColor = [UIColor blackColor].CGColor;
    view.layer.borderWidth = 2.0f;



    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(contentPad, 0, contentWidth, 22)];
    [titleLabel setFont:[UIFont systemFontOfSize:17.0]];
    titleLabel.text = [marker title];

    UILabel *descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(contentPad, 24, contentWidth, 80)];
    [descriptionLabel setFont:[UIFont systemFontOfSize:12.0]];
    descriptionLabel.numberOfLines = 5;
    descriptionLabel.text = [marker snippet];

    [view addSubview:titleLabel];
    [view addSubview:descriptionLabel];


    [outerView addSubview:view];

    return outerView;

}

这篇关于将标注添加到GMSMapview的自定义infoMarkerWindow实现中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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