How to launch Google Maps or Apple Maps from an iOS app

Today Google announced their much-anticipated Google Maps app for iOS. They also plan to make available a Google Maps SDK for iOS allowing iOS developers to integrate Google Maps in their apps, however at present API keys are only available for selected developers.

If you want to provide your app’s users with the ability to open a location in Google Maps, there is an option which works today: Google have added a comgooglemaps URL scheme to their app so third-party apps can launch the Google Maps app.

Assuming you’d like to give your users a choice of opening a location in both Apple or Google maps, you can set up some code like this in a new view controller:

#import "ViewController.h"
#import <MapKit/MapKit.h>

@implementation ViewController

- (void)viewDidLoad
    [super viewDidLoad];
    // Add a button to pop open an action sheet
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    btn.frame = CGRectMake(80,100,160,50);
    [btn setTitle:@"Open placemark" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(openActionSheet:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];

-(void)openActionSheet:(id)sender {
    //give the user a choice of Apple or Google Maps
    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Open in Maps" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:@"Apple Maps",@"Google Maps", nil];
    [sheet showInView:self.view];
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    //coordinates for the place we want to display
    CLLocationCoordinate2D rdOfficeLocation = CLLocationCoordinate2DMake(31.20691,121.477847);
    if (buttonIndex==0) {
	//Apple Maps, using the MKMapItem class
        MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:rdOfficeLocation addressDictionary:nil];
        MKMapItem *item = [[MKMapItem alloc] initWithPlacemark:placemark]; = @"ReignDesign Office";
        [item openInMapsWithLaunchOptions:nil];
    } else if (buttonIndex==1) {
        //Google Maps
        //construct a URL using the comgooglemaps schema
        NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"comgooglemaps://?center=%f,%f",rdOfficeLocation.latitude,rdOfficeLocation.longitude]];
        if (![[UIApplication sharedApplication] canOpenURL:url]) {
            NSLog(@"Google Maps app is not installed");
            //left as an exercise for the reader: open the Google Maps mobile website instead!
        } else {
            [[UIApplication sharedApplication] openURL:url];

Here’s the app in action, example code is on Github.


For more details, see the Google Maps URL Scheme documentation.

Matt Mayer

Matt Mayer is a founder at ReignDesign. Matt is from the UK and was based in Shanghai for ten years. He is now living in Bangkok, Thailand.


Leave a Reply

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

Share this post