alku83 alku83 - 4 months ago 94
iOS Question

iOS 10 heading arrow for MKUserLocation dot

The Maps app in iOS 10 now includes a heading direction arrow on top of the

. Is there some way I can add this to
in my own apps?

enter image description here

Edit: I'd be happy to do this manually, but I'm not sure if it's possible? Can I add an annotation to the map and have it follow the user's location, including animated moves?


I solved this by adding a subview to the MKUserLocation annotationView, like so

func mapView(mapView: MKMapView, didAddAnnotationViews views: [MKAnnotationView]) {
if annotationView.annotation is MKUserLocation {

func addHeadingViewToAnnotationView(annotationView: MKAnnotationView) {
    if headingImageView == nil {
        if let image = UIImage(named: "icon-location-heading-arrow") {
            let headingImageView = UIImageView()
            headingImageView.image = image
            headingImageView.frame = CGRectMake((annotationView.frame.size.width - image.size.width)/2, (annotationView.frame.size.height - image.size.height)/2, image.size.width, image.size.height)
            self.headingImageView = headingImageView

    if let headingImageView = headingImageView {
        annotationView.insertSubview(headingImageView, atIndex: 0)

    //use CoreLocation to monitor heading here, and rotate headingImageView as required