What I'm Doing...

Gasmacken 3.0 approved

Gasmacken 3.0 is now available in the App Store. It took about 5 days waiting for review and about 45 minutes to be reviewed.
The major new feature is more countries available, Sweden, Germany, Austria, Switzerland, Italy and Finland.

  • CNG stations for Sweden, Germany, Italy, Austria, Switzerland and Finland. More to come.
  • Possible to dynamically add new countries
  • Remember old position between restarts both in list and map
  • German localization
  • Digg
  • del.icio.us
  • Facebook
  • StumbleUpon
  • Google Bookmarks
  • Reddit

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

Golfkartan tillgänglig i iTunes App store

Nu finns JAKERI ABs tredje iPhone-applikation, Golfkartan tillgänglig i iTunes App store.

iTunes App store

Se pressrelease för Golfkartan.

Golfkartan ger dig tillgång till alla Sveriges golfbanor direkt i din iPhone.
Funktioner
Visar alla svenska golfbanor på en karta
Lista i bokstavsordning med alla golfbanor
Telefonnummer och emailadress till varje golfbana
Ring eller maila direkt från programmet genom att klicka på telefonnummer eller email
Mer information direkt tillgänglig via http://www.golf.se för varje golfbana
Positionering med inbyggd GPS
Möjlighet att välja mellan karta, hybrid eller satellit
Automatisk uppdatering av listan med golfbanor
Möjlighet till vägbeskrivning med inbyggd kartapplikation
Golfkartan gives you access to all golf courses in Sweden through your iPhone
Features
Show all swedish golf courses on a map
List all golf courses alphabetically
Phone number and email address
Call or email directly from the application by tapping on the phone number or email address
More information directly available from http://www.golf.se for each golf course
Show your current location with built in GPS
Choose between map, hybrid or satellite view
Automatic updates of golf courses
Show directions with with built in Maps application

Golfkartan ger dig tillgång till alla Sveriges golfbanor direkt i din iPhone.

Funktioner

  • Visar alla svenska golfbanor på en karta
  • Lista i bokstavsordning med alla golfbanor
  • Telefonnummer och emailadress till varje golfbana
  • Ring eller maila direkt från programmet genom att klicka på telefonnummer eller email
  • Mer information direkt tillgänglig via http://www.golf.se för varje golfbana
  • Positionering med inbyggd GPS
  • Möjlighet att välja mellan karta, hybrid eller satellit
  • Automatisk uppdatering av listan med golfbanor
  • Möjlighet till vägbeskrivning med inbyggd kartapplikation
  • Digg
  • del.icio.us
  • Facebook
  • StumbleUpon
  • Google Bookmarks
  • Reddit

Custom callout bubble in MKMapView, final solution!

Once again, this post has been updated.

I was not completely satisfied with my prior solution to custom callout bubble in MKMapView due a drawback.

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?

Fortunately I figured out a new solution for the problem! A much more simple solution too.

It is a combination of the property change listener solution and moving the calloutOffset off the display.

Set the calloutOffset off the display and add an observer to the selected-property.
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation {

MKAnnotationView* annotationView = nil;

MyAnnotation *myAnnotation = (MyAnnotation*) annotation;
NSString* identifier = @"Pin";
MKPinAnnotationView* annView = (MKPinAnnotationView*)[self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];

if(nil == annView) {
annView = [[[MKPinAnnotationView alloc] initWithAnnotation:myAnnotation reuseIdentifier:identifier] autorelease];
}
//Add an observer for the selected-property on the MKAnnotationView. Delegate to self.
[annView addObserver:self
forKeyPath:@"selected"
options:NSKeyValueObservingOptionNew
context:GMAP_ANNOTATION_SELECTED];

[annView setPinColor:MKPinAnnotationColorGreen];

//Set calloutOffset off screen.
CGPoint notNear = CGPointMake(10000.0,10000.0);
annView.calloutOffset = notNear;
annotationView = annView;

[annotationView setEnabled:YES];
[annotationView setCanShowCallout:YES];

return annotationView;
}

Implement the observeValueForKeyPath method. It will be triggered when the property is selected or deselected.

- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context{

NSString *action = (NSString*)context;

if([action isEqualToString:GMAP_ANNOTATION_SELECTED]){
BOOL annotationAppeared = [[change valueForKey:@"new"] boolValue];
if (annotationAppeared) {
[self showAnnotation:((MyAnnotationView*) object).annotation];
}
else {
NSLog(@"annotation deselected %@", ((MyAnnotationView*) object).annotation.title);
[self hideAnnotation];
}
}
}

Screenshot_17

Take a look at my new example (with standard MKPinAnnotationView) or with custom annotation view.

  • Digg
  • del.icio.us
  • Facebook
  • StumbleUpon
  • Google Bookmarks
  • Reddit

Gasmacken 2.0

Nu finns Gasmacken 2.0 tillgänglig för nedladdning.

Gasmacken

Nyheterna är

  • Priser, betalmetoder, kontaktinformation, öppettider, ägare och extra information
  • Buggfixar
  • Ny layout kartbubblan
  • Ny sida innehållande all information om ett tankställe
  • Möjlighet till att tvinga omläsning av datafilen
  • Digg
  • del.icio.us
  • Facebook
  • StumbleUpon
  • Google Bookmarks
  • Reddit

Custom callout bubble to MKMapView in iPhone

UPDATE! FOUND A NEW SOLUTION!

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.

custom callout bubble

A recap of what you can do with the built in callout bubble.

  • MKAnnotation contains title, subtitle and coordinate
  • Title must be set in the MKAnnotation to get the callout bubble
  • You can customize left or right of the callout bubble (MKAnnotationView) with a UIView but not change the callout bubble design at all

One solution (almost) might be to use a property change listener 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.

My solution, inspired by drawing polylines or routes on a MKMapView, has to do with adding a subview (TouchView see code in example) on top of the MKMapView and writing invisible buttons on the annotations.


#import
#import

@class UIView;

@interface TouchView : UIView {
MKMapView *mapView;
id delegate;
SEL callAtHitTest;
SEL callAtAnnotationClick;
NSMutableArray* buttonToAnnotation;
}
@property (nonatomic, assign) MKMapView * mapView;
@property (assign) id delegate;
@property (assign) SEL callAtHitTest;
@property (assign) SEL callAtAnnotationClick;

- (void) regionChange;
@end

  • Selector callAtHitTest 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.
  • Selector callAtAnnotationClick will be called when you click your annotation. This is where you make your custom callout bubble visible.
  • Method regionChange must be called every time MKMapView is changed.

In a UIView sub class

  1. Create a TouchView, set delegate and the two selectors, callAtHitTest and callAtAnnotationClick.
  2. Add MKMapView as a subview to your newly created touchView. Implement MKMapViewDelegate regionDidChangeAnimated. Call method regionChanged in your TouchView class.
  3. Populate MKMapView with annotations.
  4. Add newly created MKMapView to your TouchView.
  5. Add TouchView to surrounding UIView.
  6. Call method regionChange once in TouchView.

Here is the viewDidLoad method from the example code.


- (void)viewDidLoad {
[super viewDidLoad];

touchView = [[TouchView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
touchView.delegate = self;
touchView.callAtHitTest = @selector(stopFollowLocation);
touchView.callAtAnnotationClick = @selector(annotationClicked:);
//Next we create the MKMapView object, which will be added as a subview of viewTouch
mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
mapView.delegate = self;
touchView.mapView = mapView;
[touchView addSubview:mapView];

//And we display everything!
[self.view addSubview:touchView];

CLLocationCoordinate2D sweLoc = {63.048230,15.685730};
MKCoordinateSpan sweSpan = MKCoordinateSpanMake(14.208889, 24.169922);
MKCoordinateRegion sweRegion = MKCoordinateRegionMake(sweLoc, sweSpan);

mapView.region = sweRegion;

//Populate some test annotations.
NSMutableArray* annotations = [[NSMutableArray alloc] init];
CLLocationCoordinate2D coord2d = {59.33984880,18.11479872};
MyAnnotation *anno = [[MyAnnotation alloc] initWithCoords:coord2d name:@"Somewhere"];
[annotations addObject:anno];
[anno release];

CLLocationCoordinate2D coord2d1 = {65.80253606,21.67445822};
MyAnnotation *anno1 = [[MyAnnotation alloc] initWithCoords:coord2d1 name:@"Nowhere"];
[annotations addObject:anno1];
[anno1 release];

CLLocationCoordinate2D coord2d2 = {55.71919202,13.15571100};
MyAnnotation *anno2 = [[MyAnnotation alloc] initWithCoords:coord2d2 name:@"Anywhere"];
[annotations addObject:anno2];
[anno2 release];

[mapView addAnnotations:annotations];

[annotations release];

//redraw buttons
[touchView regionChange];

}

Remember to NOT set title and subtitle in your implementation of MKAnnotation. 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.

You might have to do some customization in your TouchView if you do not use the standard MKPinAnnotationView. Change CGRect coordinates for the buttons in TouchView to match your custom annotation view. Change UIButtonTypeRoundedRect to see the actual button and match it to cover your custom annotation view.

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. Someone out there might have a good solution for it?

That’s it. Download example for better understanding. See this post instead.

  • Digg
  • del.icio.us
  • Facebook
  • StumbleUpon
  • Google Bookmarks
  • Reddit

Gasmacken 2.0 sent to Apple for review

Gasmacken 2.0 was submitted for review to iTunes App store last friday. It usually takes 1.5 to 2 weeks before approved (if no bugs or violations found).

More information presented to the user. Such as prices, opening hours, owner, contact information and extra information.

  • Digg
  • del.icio.us
  • Facebook
  • StumbleUpon
  • Google Bookmarks
  • Reddit

Gasmacken på Aftonbladet

Aftonbladet skriver om Gasmacken!
Screen shot 2009-10-12 at 17.22.18

  • Digg
  • del.icio.us
  • Facebook
  • StumbleUpon
  • Google Bookmarks
  • Reddit

Gasmacken available for sale

My latest iPhone application Gasmacken has been approved by Apple!

Gasmacken

Gasmacken is an application that automatically fetches an updated list of all CNG (Compressed Natural Gas) refuelling stations in Sweden and displays them on a map.

Features

  • List all CNG stations in Sweden
  • Show your current location
  • Automatic updates of CNG stations in Sweden
  • Show directions with with built in Maps application

Swedish information about Gasmacken

Gasmacken är ett program som automatiskt hämtar en uppdaterad lista över alla gasmackar i Sverige och presenterar dem på en karta.

Funktioner

  • Lista med alla tankställen för fordonsgas i Sverige
  • Positionering med inbyggd GPS
  • Automatisk uppdatering av listan med tankställen för fordonsgas
  • Vägbeskrivning med inbyggd kartapplikation

Screenshot 2009.09.25 22.39.53Screenshot 2009.09.25 22.40.18

  • Digg
  • del.icio.us
  • Facebook
  • StumbleUpon
  • Google Bookmarks
  • Reddit

UILocalizedIndexedCollation, no Swedish localization

In my latest app, Gasmacken I tried to use UILocalizedIndexedCollation (from example TableViewSuite example 3) for creating a localized version of the A-Z list (A-Ö in swedish) on the right side in a table view. But to my surprise I could not get any difference in table view running in Swedish or English. The list was created in english locale. Apples example TableViewSuite uses UILocalizedIndexedCollation and does not work either.

TableViewSuite example 3

TableViewSuite example 3 running with swedish locale, no A-Ö

I trashed the use of UILocalizedIndexedCollation and created the list manually, without localization support it only supports A-Ö sorting now. Should I classify this as a bug and report it to Apple?

Screenshot 2009.09.25 22.40.18

This is what I wanted from UILocalizedIndexedCollation

Does it support any other locales, Japanese, German, French, Chinese etc? Not Swedish as I thought.

Excerpt from documentation of UILocalizedIndexedCollation.

The UILocalizedIndexedCollation class is a convenience for organizing, sorting, and localizing the data for a table view that has a section index. The table view’s data source then uses the collation object to provide the table view with input for section titles and section index titles.

Table views with section indexes are ideal for displaying and facilitating the access of data composed of many items organized by a sequential ordering scheme such as the alphabet. Users tap an index title to jump to the corresponding section. The initial table view of the Phone/Contacts application on the iPhone is an example. Note that the section titles can be different than the titles of the index.

  • Digg
  • del.icio.us
  • Facebook
  • StumbleUpon
  • Google Bookmarks
  • Reddit