Helllo Ast
Helllo Ast

Reputation: 75

How to keep an MKAnnotation View Image fixed on the center of the map as the user pans and moves the map around (iOS 6)?

using iOS 6 MapKit, I would like to define an MKAnnotation (such as a pin, or a custom one) that remains fixed on the center of the map view as the user moves the map around. Once the user stops moving the map, I would like to be able to read the new coordinates of the annotation. How can I do this?

Thanks

Upvotes: 2

Views: 922

Answers (2)

Daniel E. Salinas
Daniel E. Salinas

Reputation: 441

I know this is a bit old but I recommend you DSCenterPinMapView

It is a custom MapView with an animated and customizable center pin useful for selecting locations in map.

You should install the Pod and then, as a solution to your question you should implement the delegate so that you can get the location where pin drops.

pinMapView.delegate = self

extension MyViewController: DSCenterPinMapViewDelegate {

    func didStartDragging() {
        // My custom actions
    }

    func didEndDragging() {
        // My custom actions
        selectedLocation = pinMapView.mapview.centerCoordinate
    }

}

Upvotes: 0

Shaun
Shaun

Reputation: 412

The easiest way is to simply add your custom UIView to your MKMapView as a subview. This means when your user moves the map it will stay fixed. You will most likely have to pass through the touch events so that users can move over your custom view but worry about that later.

When your map view stops moving take its center coordinate. The MKMapView can calculate its coordinate based on its center etc [mapView centerCoordinate];

Upvotes: 2

Related Questions