OGeek|极客世界-中国程序员成长平台

标题: ios - 如何在 GMSMarker Google 上制作自定义 UIView OR 标签 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 14:48
标题: ios - 如何在 GMSMarker Google 上制作自定义 UIView OR 标签

我必须在 IOS 的 Google map 的 Marker pin 上添加自定义标签。

我已经实现了markerInfoWindow 方法。但是在我点击标记/别针后它就可以工作了。

我需要在开始时显示自定义标签,只要 mapview 将在 View 上加载而不执行任何操作。由于我们可以在标记上设置图标或标题,因此我需要在其上显示我自己的自定义 View 。

- (UIView *)mapViewGMSMapView *)mapView markerInfoWindowGMSMarker *)marker {

CLLocationCoordinate2D anchor = marker.position;

   // CGPoint point = [mapView.projection pointForCoordinate:anchor];

   // self.calloutView.title = marker.title;
    [self.calloutView setFrame:CGRectMake(0, 50, 25, 25)];
    self.calloutView.layer.cornerRadius = 11.0;
    self.calloutView.layer.masksToBounds = YES;
    self.calloutView.layer.borderColor = [UIColor clearColor].CGColor;
    self.calloutView.layer.borderWidth = 0.0;
    self.calloutView.hidden = NO;

    return self.calloutView;
}



Best Answer-推荐答案


使用此代码为 GMSMarker 添加图像:

GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = MARKER_POSITION;
marker.infoWindowAnchor = CGPointMake(0.44f, 0.45f);
marker.icon = [UIImage imageNamed"CustomMarkerImageName"];

您还可以使用此委托(delegate)方法为其他信息提供自定义 View :

- (UIView *)mapViewGMSMapView *)mapView markerInfoWindowGMSMarker *)marker {
  InfoWindow *view =  [[[NSBundle mainBundle] loadNibNamed"InfoWindow" owner:self options:nil] objectAtIndex:0];
  view.name.text = @"lace Name";
  view.description.text = @"lace description";
  view.phone.text = @"123 456 789";
  view.placeImage.image = [UIImage imageNamed"customPlaceImage"];
  view.placeImage.transform = CGAffineTransformMakeRotation(-.08);
  return view;
}

检查此答案作为引用:https://stackoverflow.com/a/16767124/2082569

关于ios - 如何在 GMSMarker Google 上制作自定义 UIView OR 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29229414/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4