5

Historic question. https://developer.apple.com/documentation/mapkit/mkusertrackingbutton is now available.


When you use the ordinary Map app on ios,

enter image description here

of course you have the blue pointer button, which cycles you through the "tracking" modes. (Show your own location, etc)

MKUserTrackingBarButtonItem does this, but it's a stupid bar button. I don't have a bar and don't want a bar, I have a normal MKMapView.

  • Can I make the "blue arrow button" simply appear on my MKMapView (nothing to do with a #$@ bar)? Much as in the above image

  • Or can I just use any old ordinary button, but have it do the same functionality?

  • Minor - if "B", in fact is there a way to get at that blue-arrow icon?

Fattie
  • 27,874
  • 70
  • 431
  • 719

3 Answers3

8

Just call addMapTrackingButton() inside viewDidLoad method:

func addMapTrackingButton(){
    let buttonItem = MKUserTrackingButton(mapView: eventsMapView)
    buttonItem.frame = CGRect(origin: CGPoint(x:5, y: 25), size: CGSize(width: 35, height: 35))

    eventsMapView.addSubview(buttonItem)
}
madx
  • 6,723
  • 4
  • 55
  • 59
3

Unfortunately, iOS doesn't expose an isolated version of MKUserTrackingBarButtonItem. (You might want to file a radar to request this. Feel free to dupe mine.)

I suggest embedding MKUserTrackingBarButtonItem in a UIToolbar with a clear background.

Community
  • 1
  • 1
Ortwin Gentz
  • 52,648
  • 24
  • 135
  • 213
1

Use MKUserTrackingButton which is UIView!

https://developer.apple.com/documentation/mapkit/mkusertrackingbutton

Kyle Yi
  • 448
  • 4
  • 11