iPhone SDK: Show address in Google Maps

As a part of the project i am currently working on (seems there is a difference between finished and FINISHED), i had to implement the pretty standard feature of displaying an address in Google Maps. To my suprise it took me quite some time to find the code, so to make things easier for others, i thought i would post it here.

If found a demo app (http://www.appsamuck.com/day3.html) that shows how to use multiple different url types (phone, email, etc.). At a glance it worked fine, but when i tried to open a Danish address with special characters (æ, ø, å), the “address” bar in Maps would just read “null”. It turned out that who ever put together the sample app, used NSASCIIStringEncoding as the format for encoding the spaces in the address – in my example i changed it to NSUTF8StringEncoding. Enjoy:

// Where is Apple in Denmark on the map anyway?
NSString* addressText = @"Nørre Voldgade 11, 1358 København K";
// URL encode the spaces
addressText = [addressText stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
// Combine url
NSString* urlText = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@", addressText];
// Open url
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlText]];

Tags: , , , , , ,

4 Responses to “iPhone SDK: Show address in Google Maps”

  1. Dr. B Says:

    Mac nerd!

  2. rakeshsoni Says:

    Thanks. really helpful

  3. eBuildy Says:


    For tel and sms, when I run the application on my iphone, I dont see any confirm alert …

    Is it still the case on the release version (I mean, do I need to do that manually?)


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: