Revisited – Custom callout bubble in MKMapView, final solution!

I thought I had the final solution for custom callout bubbles in MKMapView but I was wrong. There were a couple of errors found after testing.

  • If you press and hold it moves focus to the real callout bubble offset 10000px right and 10000px down
  • It did not work on the iPad (iPhoneOS 3.2) and iPhoneOS 4.0
  • There is a leak on the property observer

My latest solution solves the first two but not the third one. It works with iPhoneOS 3.0, 3.1, 3.2 and 4.0. I have only tested in simulator for 3.2 and 4.0.

To make it a easier to look at the code I have created my first github repository. You can alsoe download source for master (zip or tar) directly from github.

Update: I got my application, Gasmacken approved (2010-05-23) with this solution.

  • Digg
  • del.icio.us
  • Facebook
  • StumbleUpon
  • Google Bookmarks
  • Reddit
This entry was posted in Development, iphone and tagged , , , , , , . Bookmark the permalink.

14 Responses to Revisited – Custom callout bubble in MKMapView, final solution!

  1. Pingback: Custom callout bubble in MKMapView, final solution! « JAKERI

  2. Boran says:

    Hello, Jakeri. Thanks for your work. :) I’ve used your final solution which is not revised one. So I faced same problems as you mentioned on this post. After I downloaded your revised solution, I tried to find differences with last version and fix some part of code in my project but it didn’t work on iPhone 4.0. The problem I got is first one, callout bubble. Could you let me know which part of code you revised for solving the problem related with callout bubble? Thanks a lot! :D

  3. Boran says:

    Sorry, I found it. Thanks.

  4. D_O_P says:

    Hello Jakeri,

    Does “leak on the property observer” you are talking about does concern the fact that you never remove the observer from the annotations view ? If so, maybe this solution would fit:

    When you create MyAnnotationView objects, add them to to a NSMutableArray list. Then, in dealloc, do:
    for (annotations id in list)
    [annotation removeObserver:self forKeyPath:@"selected"];

    Do you think this would solve the problem ?

    By the way, I have a question: where have you gathered the information to write this line:
    [UIView beginAnimations: @"moveCNGCallout" context: nil];
    in particular, the “moveCNGCallout” thing ?

    Thanks a lot, your tutorial is helpful :)

  5. D_O_P says:

    Waouw, sorry, I have sent to quickly my comment. Some little mistakes :
    for (id annotation in list) //instead of “annotation id”
    [annotation removeObserver:self forKeyPath:@"selected"];

  6. admin says:

    Hi,

    I tried some stuff with dealloc and the warning but I found out something that I can not remember right now. I believe that it had todo something with the order of dealloc and calling removeObserver.

    If you find a solution please clone my github repo and I will merge it into master.

  7. neil says:

    Not working for me (iOS 4.1, iPhone4). After tapping an annotation the map positions somewhere around the south pole…

  8. admin says:

    I got iOS 4.1 and have no problem at all. My apps are live on App store and I have not gotten any complaints.

  9. neil says:

    Maybe, but the sample code, fresh loaded from github doesn’t even show usable results in the simulator. Can provide a video, if you like…

  10. admin says:

    Strange, I will give it a try again.

  11. neil says:

    I’m using XCode 3.2.4, 1708, 4.1 SDK, if that matters, so the latest.
    Regards

  12. Tobycakes says:

    This code is great. There is this one little issue though:
    When you select an annotation, it shows the view. However, when you click the annotation again, it hides then shows the view. I think it would make more sense if it just hid the view… click to show, click to hide.

  13. edd says:

    great stuff! :-)
    many thanks, you saved my day!!

  14. Tobycakes says:

    The other thing I can’t work out is why stopFollowLocation gets called three times whenever I tap or drag on the map, or click an annotation.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>