gpt4 book ai didi

uiview - 将标注添加到 GMSMapview 的自定义 infoMarkerWindow 实现

转载 作者:行者123 更新时间:2023-12-02 04:57:52 26 4
gpt4 key购买 nike

我正在使用 Google IOS SDK 并且已经实现了

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

实现自定义 View 。当我显示此 View 时,它不会像 Google map View 通常为其自己的标记那样添加标注。谁能告诉我如何添加此标注,例如指向此自定义 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;

}

关于uiview - 将标注添加到 GMSMapview 的自定义 infoMarkerWindow 实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17635741/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com