Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I launch the Google Maps iPhone application from within my own native application?

The Apple Developer Documentation (link is dead now) explains that if you place a link in a web page and then click it whilst using Mobile Safari on the iPhone, the Google Maps application that is provided as standard with the iPhone will launch.

How can I launch the same Google Maps application with a specific address from within my own native iPhone application (i.e. not a web page through Mobile Safari) in the same way that tapping an address in Contacts launches the map?

NOTE: THIS ONLY WORKS ON THE DEVICE ITSELF. NOT IN THE SIMULATOR.

like image 900
davidmytton Avatar asked Aug 27 '08 13:08

davidmytton


People also ask

Can you use Google Maps in your own app?

You can use the Google Maps Platform within your applications as long as your site meets the Google Maps Platform Terms of Service.

How do I make Google Maps open automatically on my iPhone?

Tap the menu icon in the top left of the search bar. Scroll down to the bottom of the menu and tap Settings. Tap Default apps. Under Navigate from your location, tap Google Maps, then under Navigate between locations, tap Google Maps again.

How do I change the default map app on my iPhone?

Tap the top-left menu icon. Scroll down and find “Settings.” Select “Default Apps.” Under “Navigate from Your Location,” select “Google Maps.”

How do I open Google Maps using iOS app Swift?

Using Swift 5 and XCode 13, I was able to use Google's Universal cross-platform syntax to open Google Maps app in directions mode. The link will open the google maps app if it is installed on the phone. If maps is not installed it will open the url in the browser.


2 Answers

For iOS 5.1.1 and lower, use the openURL method of UIApplication. It will perform the normal iPhone magical URL reinterpretation. so

[someUIApplication openURL:[NSURL URLWithString:@"http://maps.google.com/maps?q=London"]] 

should invoke the Google maps app.

From iOS 6, you'll be invoking Apple's own Maps app. For this, configure an MKMapItem object with the location you want to display, and then send it the openInMapsWithLaunchOptions message. To start at the current location, try:

[[MKMapItem mapItemForCurrentLocation] openInMapsWithLaunchOptions:nil]; 

You'll need to be linked against MapKit for this (and it will prompt for location access, I believe).

like image 99
Adam Wright Avatar answered Sep 26 '22 05:09

Adam Wright


Exactly. The code that you need to achieve this is something like that:

UIApplication *app = [UIApplication sharedApplication]; [app openURL:[NSURL URLWithString: @"http://maps.google.com/maps?q=London"]]; 

since as per the documentation, UIApplication is only available in the Application Delegate unless you call sharedApplication.

like image 24
davidmytton Avatar answered Sep 26 '22 05:09

davidmytton