Uiview 为GMSMapview的自定义infoMarkerWindow实现添加标注
我正在使用Google IOS SDK并已实现Uiview 为GMSMapview的自定义infoMarkerWindow实现添加标注,uiview,google-maps-sdk-ios,Uiview,Google Maps Sdk Ios,我正在使用Google IOS SDK并已实现 - (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker 实现自定义视图。当我显示此视图时,它不会像谷歌地图视图通常为自己的标记添加标注。有人能告诉我如何才能添加指向此自定义MakerInfo窗口标记的类似标注的指针吗?此方法是一种GMSMapViewDelegate方法,您是否将代理设置为视图控制器 mapView.delegate = self
- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker
实现自定义视图。当我显示此视图时,它不会像谷歌地图视图通常为自己的标记添加标注。有人能告诉我如何才能添加指向此自定义MakerInfo窗口标记的类似标注的指针吗?此方法是一种
GMSMapViewDelegate
方法,您是否将代理设置为视图控制器
mapView.delegate = self;
下面是如何做到这一点
- (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;
}
是的,它显示的是自定义视图-但我的问题是如何显示谷歌为自己的标记显示的小标注标记…你有你所说的屏幕截图吗?我对您所说的标注标记有点困惑。也许你最好提供makerInforWindow方法的一些代码,这样我们就可以找出问题所在……我已经解决了,我会发布代码。我所说的是显示底部指向标记的小三角形,以提供一个视觉指示,表明此信息窗口属于此特定标记。我正在用代码创建一个小视图,并进行仿射变换,使其看起来像底部的三角形。