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.
Pingback: Custom callout bubble in MKMapView, final solution! « JAKERI
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!
Sorry, I found it. Thanks.
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
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"];
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.
Not working for me (iOS 4.1, iPhone4). After tapping an annotation the map positions somewhere around the south pole…
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.
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…
Strange, I will give it a try again.
I’m using XCode 3.2.4, 1708, 4.1 SDK, if that matters, so the latest.
Regards
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.
great stuff!
many thanks, you saved my day!!
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.