Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MKUserTrackingBarButtonItem functionality, but not in a stupid bar button

Tags:

ios

iphone

mapkit

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?

like image 553
Fattie Avatar asked Apr 17 '17 16:04

Fattie


1 Answers

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)
}
like image 116
madx Avatar answered Sep 30 '22 16:09

madx