How to Launch the Google Maps iPhone Application from Within My Own Native Application

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

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).

How to return native app from google map in ios

In the Google Maps Documentation section about the URL scheme there is an example of how the callbackl should work.

  • x-source The name of the application sending the x-callback request.
    Short names are preferred.
  • x-success — The URL to call when complete.
    Often this will be a URL scheme for your own app, allowing users to
    return to the original application.

For example:

comgooglemaps-x-callback://?center=40.765819,-73.975866&zoom=14
&x-success=sourceapp://?resume=true
&x-source=SourceApp

Here you see the x-success property, which should be set to your app URL scheme and the x-source is the name of your app as presented in Google Maps app return to app bar.

Cant open google maps from my native ios app with url comgooglemaps-x-callback://

You can open google maps using comgooglemaps:// only.

if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"comgooglemaps://"]]) {

NSString* url = [NSString stringWithFormat: @"comgooglemaps://?daddr=%@&directionsmode=driving", encodedString];

[[UIApplication sharedApplication] openURL:[NSURL URLWithString: url] options:@{} completionHandler:^(BOOL success) {
if (success) {
//do something on success
}
}];

} else {
//if google map is not installed in device then we can open goole map in web
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://maps.google.com/maps?daddr=%@", encodedString]] options:@{} completionHandler:^(BOOL success) {
if (success) {
//do something on success
}
}];
}

Don't forget to include in Info.plist like below.

LSApplicationQueriesSchemes


comgooglemaps


Sample Image

mobile site, click google map to open native google map app

You may wanna check the following links:

-For iOS:

  • Opening native google maps in Xcode

-For Android:

  • Android - launch google map via web url

Hope this helps.

Embed native Google Maps into a mobile application

In Android you should use MapViews and MapActivities.

More info:

Android Doc

The books Android Recipes A Problem-Solution Approach and The Busy Coder's Guide to Android Development both have a nice chapter for solving your problem



Related Topics



Leave a reply



Submit