Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8880441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:09:57+00:00 2026-06-14T20:09:57+00:00

I have an app in which I allow users to launch the Maps App

  • 0

I have an app in which I allow users to launch the Maps App (Google or Apple) to view an address.

I used to do this:

Address *address = [self.person.addresses objectAtIndex:0]; 

NSString *addressString = [NSString stringWithFormat:@"%@ %@ %@ %@, %@ %@",
                                   address.line1 == nil ? @"" : address.line1,
                                   address.line2 == nil ? @"" : address.line2,
                                   address.line3 == nil ? @"" : address.line3,
                                   address.city == nil ? @"" : address.city,
                                   address.state == nil ? @"" : address.state,
                                   address.zip == nil ? @"" : address.zip];

NSString *mapsURL = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@", [addressString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:mapsURL]];

But to support iOS 6, I’ve changed it to this:

Address *address = [self.person.addresses objectAtIndex:0]; 

        NSString *addressString = [NSString stringWithFormat:@"%@ %@ %@ %@, %@ %@",
                                   address.line1 == nil ? @"" : address.line1,
                                   address.line2 == nil ? @"" : address.line2,
                                   address.line3 == nil ? @"" : address.line3,
                                   address.city == nil ? @"" : address.city,
                                   address.state == nil ? @"" : address.state,
                                   address.zip == nil ? @"" : address.zip];

        // Check for iOS 6
        Class mapItemClass = [MKMapItem class];
        if (mapItemClass && [mapItemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)])
        {
            /*
            // Create an MKMapItem to pass to the Maps app
            MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:nil
                                                           addressDictionary:nil];

            MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark];
            [mapItem openInMapsWithLaunchOptions:nil];
            */

            // I want something like this:
            MKMapItem *mapItem = [[MKMapItem alloc] initWithAddressQuery:addressString];
            [mapItem openInMapsWithLaunchOptions:nil];
        }
        else
        {
            NSString *mapsURL = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@", [addressString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:mapsURL]];

        }

Basically, with the raw address (no ABPersonRef‘s or anything) I need to open the location in Apple Maps. Google used to do this just fine.

I’ve tried the simple switch from maps.google.com to maps.apple.com but in iOS 5 it opens to Google Maps web app — which I don’t want! There’s a perfectly good native app.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:09:57+00:00Added an answer on June 14, 2026 at 8:09 pm

    Found the answer here. It is accomplished by using the CLGeocoder class:

    // Check for iOS 6
        Class mapItemClass = [MKMapItem class];
        if (mapItemClass && [mapItemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)])
        {
            CLGeocoder *geocoder = [[CLGeocoder alloc] init];
            [geocoder geocodeAddressString:addressString
                         completionHandler:^(NSArray *placemarks, NSError *error) {
    
                             // Convert the CLPlacemark to an MKPlacemark
                             // Note: There's no error checking for a failed geocode
                             CLPlacemark *geocodedPlacemark = [placemarks objectAtIndex:0];
                             MKPlacemark *placemark = [[MKPlacemark alloc]
                                                       initWithCoordinate:geocodedPlacemark.location.coordinate
                                                       addressDictionary:geocodedPlacemark.addressDictionary];
    
                             // Create a map item for the geocoded address to pass to Maps app
                             MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark];
                             [mapItem setName:geocodedPlacemark.name];
    
                             // Set the directions mode to "Driving"
                             // Can use MKLaunchOptionsDirectionsModeWalking instead
                             NSDictionary *launchOptions = @{MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving};
    
                             // Get the "Current User Location" MKMapItem
                             MKMapItem *currentLocationMapItem = [MKMapItem mapItemForCurrentLocation];
    
                             // Pass the current location and destination map items to the Maps app
                             // Set the direction mode in the launchOptions dictionary
                             [MKMapItem openMapsWithItems:@[currentLocationMapItem, mapItem] launchOptions:launchOptions];
    
                         }];
        }
        //iOS 4/5:
        else
        {
            NSString *mapsURL = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@", [addressString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
            ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PDF document in my app which I want to allow users
I have created an app which allows users to buy non-consumable content. The retrieving-ids-payment-process
I have created an app which allows users to buy non-consumable content. The retrieving-ids-payment-process
I have a flex app which allows user to create some content. this content
I have an iOS app with a UITableView that has flexible width, which allow
I have a fairly simple site which allow users to connect via facebook. I
I have created a link on my app to allow users to create appointments,
I have a web app(jsp/servlets) which allows users to download audio files and play
I have a download link in my app from which users should be able
In my app I have a plugin system that allow users to develop plugins

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.