Google Maps iOS SDK: Custom marker iconView with SwiftUI - Stack Overflow

I am trying to create a custom iconView using SwiftUI for may Google Maps markers:struct CustumMarkerV

I am trying to create a custom iconView using SwiftUI for may Google Maps markers:

struct CustumMarkerView: View {
  let inter15_500 = Font.inter(size: 15, weight: 500)
  let destination: POILocation
  
  var iconName: String {
    switch destination.locationType.id {
    case 1:
      return "airplane"
    case 2:
      return "bus"
    case 3:
      return "train.side.front.car"
    case 4:
      return "building.2"
    default:
      return "party.popper"
    }
  }
  
  var body: some View {
    HStack(alignment: .center, spacing: 4) {
      Text(destination.name)
        .font(inter15_500)
        .foregroundStyle(Theme.Color.black2)
        .lineLimit(1)
      Image(systemName: iconName)
        .resizable()
        .renderingMode(.template)
        .aspectRatio(contentMode: .fit)
        .padding(8)
        .frame(width: 32, height: 32)
        .background(Theme.Color.black6)
        .foregroundStyle(.white)
        .clipShape(.circle)
    }
    .frame(height: 32)
  }
}

@MainActor
class CustomMarker: GMSMarker {
  
  let destination: POILocation
  
  init(destination: POILocation) {
    self.destination = destination
    super.init()
    
    let swiftUIView = UIHostingController(rootView: CustumMarkerView(destination: destination)).view!
    swiftUIView.translatesAutoresizingMaskIntoConstraints = false
    swiftUIView.backgroundColor = .green
    //swiftUIView.heightAnchor.constraint(equalToConstant: 32).isActive = true
    self.iconView = swiftUIView
    self.appearAnimation = .fadeIn
    
    self.position = .init(
      latitude: Double(destination.coordinate.latitude) ?? 0,
      longitude: Double(destination.coordinate.longitude) ?? 0
    )
  }
}

If I don't add a height constraint it becomes like this:

If I add a height constraint it becomes like this:

Can anyone help me fix it?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745604271a4635582.html

相关推荐

  • Google Maps iOS SDK: Custom marker iconView with SwiftUI - Stack Overflow

    I am trying to create a custom iconView using SwiftUI for may Google Maps markers:struct CustumMarkerV

    11小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信