Custom button for compass Button

I am trying to add a custom compass button in the map but nothing appears, I am trying with a button

self .controlView.setCompassButton( self .compassButton, withDefaultConstraints: true )

but nothing appears.

1 Like

Which version of the SDK you are using?

the latest version (2.4.59) but this method is not available in the documentation


We have a nice Maps Examples application which covers majority of the SDK features including this one. Please take a look at the source code here:

I hope this helps a little bit.

I am using the latest version of the SDK but the compass button method in the example is deprecated. when I was using the older version the code works fine

Hi @yethindias.

Can you try to use the following code?

let customCompassButton = UIButton()
customCompassButton.setImage(UIImage(named: "custom_compass"), for: .normal)
customCompassButton.setImage(UIImage(named: "custom_compass"), for: .highlighted)
customCompassButton.setImage(UIImage(named: "custom_compass"), for: .selected)
controlView.setCompassButton(customCompassButton, withDefaultConstraints: false)
controlView.compassButton?.translatesAutoresizingMaskIntoConstraints = false
controlView.compassButton?.topAnchor.constraint(equalTo: view.topAnchor,constant: 20).isActive = true
controlView.compassButton?.rightAnchor.constraint(equalTo: view.rightAnchor,constant: -20).isActive = true
controlView.compassButton?.widthAnchor.constraint(equalToConstant: 40).isActive = true
controlView.compassButton?.heightAnchor.constraint(equalToConstant: 40).isActive = true