Code: Custom pins in your map

Sometimes you need to add a custom pin to your map. You can use this piece of code to achieve that.

Take a special look to the property “centerOffset” that allows to adjust your image from the center of your MKAnnotationView (usually you will set it as (0 , minus half of the height of your image).

An example without correcting the centerOffset property:


And this one correcting the centerOffset and setting it to (0,-halfImage):

Captura de pantalla 2014-01-04 a la(s) 13.08.51

Be careful with the class you use for adding the pin to the map. To be able to set the centerOffset you need to use MKAnnotationView, instead of MKPinAnnotatioView… because in this one the property centerOffset works in an unpredictable way.