<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JAKERI &#187; mkannotationview</title>
	<atom:link href="http://www.jakeri.net/tag/mkannotationview/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jakeri.net</link>
	<description>Consulting/Development in Java, Objective-C for web based systems and iPhone</description>
	<lastBuildDate>Sun, 23 May 2010 20:04:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Revisited &#8211; Custom callout bubble in MKMapView, final solution!</title>
		<link>http://www.jakeri.net/2010/05/custom-callout-bubble-final-solution-revisited/</link>
		<comments>http://www.jakeri.net/2010/05/custom-callout-bubble-final-solution-revisited/#comments</comments>
		<pubDate>Sun, 16 May 2010 18:03:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[callout bubble]]></category>
		<category><![CDATA[google maps]]></category>
		<category><![CDATA[mkannotation]]></category>
		<category><![CDATA[mkannotationview]]></category>
		<category><![CDATA[mkmapview]]></category>
		<category><![CDATA[property change listener]]></category>

		<guid isPermaLink="false">http://www.jakeri.net/?p=392</guid>
		<description><![CDATA[<p>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.</p>

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 [...]]]></description>
			<content:encoded><![CDATA[<p>I thought I had the <a href="http://www.jakeri.net/2009/12/custom-callout-bubble-in-mkmapview-final-solution/">final solution for custom callout bubbles in MKMapView</a> but I was wrong. There were a couple of errors found after testing.</p>
<ul>
<li>If you press and hold it moves focus to the real callout bubble offset 10000px right and 10000px down</li>
<li>It did not work on the iPad (iPhoneOS 3.2) and iPhoneOS 4.0</li>
<li>There is a leak on the property observer</li>
</ul>
<p>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.</p>
<p>To make it a easier to look at the code I have created my first <a href="http://github.com/jakeri/CustomCalloutMapView">github repository</a>. You can alsoe download source for master (<a href="http://github.com/jakeri/CustomCalloutMapView/zipball/master">zip</a> or <a href="http://github.com/jakeri/CustomCalloutMapView/tarball/master">tar</a>) directly from github.</p>
<p><strong>Update:</strong> I got my <a href="http://www.jakeri.net/gasmacken">application</a>, <a href="http://www.jakeri.net/gasmacken">Gasmacken</a> approved (2010-05-23) with this solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jakeri.net/2010/05/custom-callout-bubble-final-solution-revisited/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Custom callout bubble in MKMapView, final solution!</title>
		<link>http://www.jakeri.net/2009/12/custom-callout-bubble-in-mkmapview-final-solution/</link>
		<comments>http://www.jakeri.net/2009/12/custom-callout-bubble-in-mkmapview-final-solution/#comments</comments>
		<pubDate>Sun, 06 Dec 2009 13:20:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[callout bubble]]></category>
		<category><![CDATA[google maps]]></category>
		<category><![CDATA[mkannotation]]></category>
		<category><![CDATA[mkannotationview]]></category>
		<category><![CDATA[mkmapview]]></category>
		<category><![CDATA[property change listener]]></category>

		<guid isPermaLink="false">http://www.jakeri.net/?p=349</guid>
		<description><![CDATA[<p>Once again, this post has been updated.</p>
<p>I was not completely satisfied with my prior solution to custom callout bubble in MKMapView due a drawback.</p>
<p>One drawback is that if you click an annotation in the TouchView it is not propagated down to the MKMapView which makes pinch zoom bit more tricky if you have many annotations. [...]]]></description>
			<content:encoded><![CDATA[<p>Once again, this post has been <a href="http://www.jakeri.net/2010/05/custom-callout-bubble-final-solution-revisited/">updated</a>.</p>
<p>I was not completely satisfied with my prior solution to <a href="http://www.jakeri.net/2009/11/custom-callout-bubble-to-mkmapview-in-iphone/">custom callout bubble in MKMapView</a> due a drawback.</p>
<blockquote><p>One drawback is that if you click an annotation in the TouchView it is not propagated down to the MKMapView which makes pinch zoom bit more tricky if you have many annotations. Someone out there might have a good solution for it?</p></blockquote>
<p>Fortunately I figured out a new solution for the problem! A much more simple solution too.</p>
<p>It is a combination of the <a href="http://blog.evandavey.com/2009/07/how-to-detect-when-mkannotation-mkannotationview-is-selected.html">property change listener</a> solution and moving the <a href="http://developer.apple.com/iphone/library/documentation/MapKit/Reference/MKAnnotationView_Class/Reference/Reference.html#//apple_ref/occ/instp/MKAnnotationView/calloutOffset">calloutOffset</a> off the display.</p>
<p>Set the calloutOffset off the display and add an observer to the selected-property.<br />
<code>- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation {</code></p>
<p><code>MKAnnotationView* annotationView = nil;</code></p>
<p><code>MyAnnotation *myAnnotation = (MyAnnotation*) annotation;<br />
NSString* identifier = @"Pin";<br />
MKPinAnnotationView* annView = (MKPinAnnotationView*)[self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];</code></p>
<p><code> </code></p>
<p><code>if(nil == annView) {<br />
annView = [[[MKPinAnnotationView alloc] initWithAnnotation:myAnnotation reuseIdentifier:identifier] autorelease];<br />
}<br />
//Add an observer for the selected-property on the MKAnnotationView. Delegate to self.<br />
[annView addObserver:self<br />
forKeyPath:@"selected"<br />
options:NSKeyValueObservingOptionNew<br />
context:GMAP_ANNOTATION_SELECTED];</code></p>
<p><code> </code></p>
<p><code>[annView setPinColor:MKPinAnnotationColorGreen];</p>
<p>//Set calloutOffset off screen.<br />
CGPoint notNear = CGPointMake(10000.0,10000.0);<br />
annView.calloutOffset = notNear;<br />
annotationView = annView;</p>
<p>[annotationView setEnabled:YES];<br />
[annotationView setCanShowCallout:YES];</p>
<p></code></p>
<p><code> return annotationView;<br />
}</code></p>
<p>Implement the observeValueForKeyPath method. It will be triggered when the property is selected or deselected.<br />
<code><br />
- (void)observeValueForKeyPath:(NSString *)keyPath<br />
ofObject:(id)object<br />
change:(NSDictionary *)change<br />
context:(void *)context{</code></p>
<p><code>NSString *action = (NSString*)context;</code></p>
<p><code> </code></p>
<p><code> if([action isEqualToString:GMAP_ANNOTATION_SELECTED]){<br />
BOOL annotationAppeared = [[change valueForKey:@"new"] boolValue];<br />
if (annotationAppeared) {<br />
[self showAnnotation:((MyAnnotationView*) object).annotation];<br />
}<br />
else {<br />
NSLog(@"annotation deselected %@", ((MyAnnotationView*) object).annotation.title);<br />
[self hideAnnotation];<br />
}<br />
}<br />
}<br />
</code></p>
<p><a href="http://www.jakeri.net/wp-content/uploads/2009/12/Screenshot_17.png"><img class="alignnone size-medium wp-image-363" title="Screenshot_17" src="http://www.jakeri.net/wp-content/uploads/2009/12/Screenshot_17-156x300.png" alt="Screenshot_17" width="156" height="300" /></a></p>
<p>Take a look at my <a href="http://www.jakeri.net/wp-content/uploads/2009/12/FinalCustomCalloutMapView.zip">new example</a> (with standard MKPinAnnotationView) or with <a href="http://www.jakeri.net/wp-content/uploads/2009/12/CustomCalloutMapView-custom-annotationView.zip">custom annotation view</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jakeri.net/2009/12/custom-callout-bubble-in-mkmapview-final-solution/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
		</item>
		<item>
		<title>Custom callout bubble to MKMapView in iPhone</title>
		<link>http://www.jakeri.net/2009/11/custom-callout-bubble-to-mkmapview-in-iphone/</link>
		<comments>http://www.jakeri.net/2009/11/custom-callout-bubble-to-mkmapview-in-iphone/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 21:37:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Company]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[callout bubble]]></category>
		<category><![CDATA[google maps]]></category>
		<category><![CDATA[mkannotation]]></category>
		<category><![CDATA[mkannotationview]]></category>
		<category><![CDATA[mkmapview]]></category>

		<guid isPermaLink="false">http://www.jakeri.net/?p=286</guid>
		<description><![CDATA[<p>UPDATE! FOUND A NEW SOLUTION!</p>
<p>My latest version, 2.0 of Gasmacken contains a solution to the very annoying problem with a creating a custom callout bubble to the MKMapView in the iPhone SDK. There are no way to get a callback from the MKMapView delegate when a callout bubble is opened.</p>
<p></p>
<p>A recap of what you can do [...]]]></description>
			<content:encoded><![CDATA[<p><strong>UPDATE! FOUND A NEW <a href="http://www.jakeri.net/2009/12/custom-callout-bubble-in-mkmapview-final-solution/">SOLUTION!</a></strong></p>
<p>My latest version, 2.0 of <a href="http://www.jakeri.net/gasmacken">Gasmacken</a> contains a solution to the very annoying problem with a creating a <a href="http://stackoverflow.com/questions/1565828/customize-callout-bubble-for-annotationview">custom</a> <a href="http://stackoverflow.com/questions/1350050/custom-mkannotationview-callout">callout</a> <a href="http://stackoverflow.com/questions/1525114/custom-popup-when-clicking-pin-in-mkmapview">bubble</a> to the MKMapView in the iPhone SDK. There are <strong>no way</strong> to get a callback from the MKMapView delegate when a callout bubble is opened.</p>
<p><a href="http://www.jakeri.net/wp-content/uploads/2009/10/Screenshot_4.jpg"><img class="aligncenter size-medium wp-image-281" title="custom callout bubble" src="http://www.jakeri.net/wp-content/uploads/2009/10/Screenshot_4-208x300.jpg" alt="custom callout bubble" width="208" height="300" /></a></p>
<p>A recap of what you can do with the built in callout bubble.</p>
<ul>
<li><a href="http://developer.apple.com/IPhone/library/documentation/MapKit/Reference/MKAnnotation_Protocol/Reference/Reference.html">MKAnnotation</a> contains title, subtitle and coordinate</li>
<li>Title must be set in the MKAnnotation to get the callout bubble</li>
<li>You can customize left or right of the callout bubble (<a href="http://developer.apple.com/iphone/library/DOCUMENTATION/MapKit/Reference/MKAnnotationView_Class/Reference/Reference.html#//apple_ref/doc/c_ref/MKAnnotationView">MKAnnotationView</a>) with a UIView but not change the callout bubble design at all</li>
</ul>
<p>One solution (almost) might be to use a <a href="http://blog.evandavey.com/2009/07/how-to-detect-when-mkannotation-mkannotationview-is-selected.html">property change listener</a> for the selected value. Unfortunately, the selected property is only changed if you have a title set in the MKAnnotation, which also brings up the built in callout bubble. This is a good solution if you e.g. want to play a sound when you open up the built in callout bubble.</p>
<p><strong>My solution</strong>, inspired by <a href="http://spitzkoff.com/craig/?p=108">drawing polylines or routes on a MKMapView</a>, has to do with adding a subview (TouchView see code in example) on top of the MKMapView and writing invisible buttons on the annotations.</p>
<p><code><br />
#import<br />
#import </code></p>
<p><code> </code></p>
<p><code>@class UIView;</code></p>
<p><code>@interface TouchView : UIView {<br />
MKMapView *mapView;<br />
id delegate;<br />
SEL callAtHitTest;<br />
SEL callAtAnnotationClick;<br />
NSMutableArray* buttonToAnnotation;<br />
}<br />
@property (nonatomic, assign) MKMapView * mapView;<br />
@property (assign) id delegate;<br />
@property (assign) SEL callAtHitTest;<br />
@property (assign) SEL callAtAnnotationClick;</p>
<p></code></p>
<p><code>- (void) regionChange;<br />
@end<br />
</code></p>
<ul>
<li>Selector <em>callAtHitTest</em> will be called every time you click on the map except for subview buttons. This method is great to use for stop follow current location updates in your code.</li>
<li>Selector <em><strong>callAtAnnotationClick</strong></em> will be called when you click your annotation. <strong>This is where you make your custom callout bubble visible.</strong></li>
<li>Method <em>regionChange</em> must be called every time MKMapView is changed.</li>
</ul>
<p>In a UIView sub class</p>
<ol>
<li>Create a TouchView, set delegate and the two selectors, <em>callAtHitTest</em> and <em>callAtAnnotationClick</em>.</li>
<li>Add MKMapView as a subview to your newly created touchView. Implement <em>MKMapViewDelegate </em><em>regionDidChangeAnimated. </em>Call method regionChanged in your TouchView class.</li>
<li>Populate MKMapView with annotations.</li>
<li>Add newly created MKMapView to your TouchView.</li>
<li>Add TouchView to surrounding UIView.</li>
<li>Call method regionChange once in TouchView.</li>
</ol>
<p>Here is the viewDidLoad method from the example code.</p>
<p><code><br />
- (void)viewDidLoad {<br />
[super viewDidLoad];</code></p>
<p><code> </code></p>
<p><code>touchView = [[TouchView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];<br />
touchView.delegate = self;<br />
touchView.callAtHitTest = @selector(stopFollowLocation);<br />
touchView.callAtAnnotationClick = @selector(annotationClicked:);<br />
//Next we create the MKMapView object, which will be added as a subview of viewTouch<br />
mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];<br />
mapView.delegate = self;<br />
touchView.mapView = mapView;<br />
[touchView addSubview:mapView];</code></p>
<p><code>//And we display everything!<br />
[self.view addSubview:touchView];</p>
<p>CLLocationCoordinate2D sweLoc = {63.048230,15.685730};<br />
MKCoordinateSpan sweSpan = MKCoordinateSpanMake(14.208889, 24.169922);<br />
MKCoordinateRegion sweRegion = MKCoordinateRegionMake(sweLoc, sweSpan);</p>
<p>mapView.region = sweRegion;</p>
<p>//Populate some test annotations.<br />
NSMutableArray* annotations = [[NSMutableArray alloc] init];<br />
CLLocationCoordinate2D coord2d = {59.33984880,18.11479872};<br />
MyAnnotation *anno = [[MyAnnotation alloc] initWithCoords:coord2d name:@"Somewhere"];<br />
[annotations addObject:anno];<br />
[anno release];</p>
<p>CLLocationCoordinate2D coord2d1 = {65.80253606,21.67445822};<br />
MyAnnotation *anno1 = [[MyAnnotation alloc] initWithCoords:coord2d1 name:@"Nowhere"];<br />
[annotations addObject:anno1];<br />
[anno1 release];</p>
<p>CLLocationCoordinate2D coord2d2 = {55.71919202,13.15571100};<br />
MyAnnotation *anno2 = [[MyAnnotation alloc] initWithCoords:coord2d2 name:@"Anywhere"];<br />
[annotations addObject:anno2];<br />
[anno2 release];</p>
<p>[mapView addAnnotations:annotations];</p>
<p>[annotations release];</p>
<p>//redraw buttons<br />
[touchView regionChange];</p>
<p></code></p>
<p><code>}<br />
</code><br />
<strong>Remember to NOT set </strong><em><strong>title</strong></em><strong> and </strong><em><strong>subtitle</strong></em><strong> in your implementation of MKAnnotation</strong>. If it is set MKMapView will show the standard callout bubble if you accidentally click outside the TouchView button but inside the standard annotation in the MKMapView.</p>
<p>You might have to do some customization in your TouchView if you <strong>do not use the standard MKPinAnnotationView</strong>. Change <strong>CGRect coordinates for the buttons in TouchView</strong> to match your custom annotation view. Change UIButtonTypeRoundedRect to see the actual button and match it to cover your custom annotation view.</p>
<p><span style="text-decoration: line-through;">One drawback is that if you click a annotation in the TouchView it is not propagated down to the MKMapView which makes pinch zoom bit more tricky if you have many annotations.</span> Someone out there might have a <a href="http://www.jakeri.net/2009/12/custom-callout-bubble-in-mkmapview-final-solution/">good solution</a> for it?</p>
<p><span style="text-decoration: line-through;">That&#8217;s it. Download </span><a href="http://www.jakeri.net/wp-content/uploads/2009/11/CustomCalloutMapView.zip"><span style="text-decoration: line-through;">example</span></a><span style="text-decoration: line-through;"> for better understanding</span>. See this <a href="http://www.jakeri.net/2009/12/custom-callout-bubble-in-mkmapview-final-solution/">post</a> instead.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jakeri.net/2009/11/custom-callout-bubble-to-mkmapview-in-iphone/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
