Reputation: 2356
I am using this code to launch google map fine.
-(void)buttonPressed:(UIButton *)sender{
NSString *urlstring=[NSString stringWithFormat:@"http://maps.google.com/?saddr=%f,%f&daddr=%f,%f",sourcelocation.latitude,sourcelocation.longitude,destinationlocation.latitude,destinationlocation.longitude];
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:urlstring]];
}
When I click on the button, the google map load. This action is in middle of my application. How can I create the back button?
Upvotes: 0
Views: 690
Reputation: 2169
The better way to do this is not to use openURL
because it will exit your application but to use a UIWebView
to view the page and push it onto a UINavigationController
:
UIViewController *webViewController = [[[UIViewController alloc] init] autorelease];
UIWebView *uiWebView = [[[UIWebView alloc] initWithFrame: CGRectMake(0,0,320,480)] autorelease];
NSString *urlstring=[NSString stringWithFormat:@"http://maps.google.com/?saddr=%f,%f&daddr=%f,%f",sourcelocation.latitude,sourcelocation.longitude,destinationlocation.latitude,destinationlocation.longitude];
[uiWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]];
[webViewController.view addSubview: uiWebView];
[self.navigationController pushViewController:webViewController animated:YES];
This assumes though that you already have the view you are pushing from in a navigation controller.
Upvotes: 2
Reputation: 2649
You can take a view with navigation bar and a uiwebview. And put a back button on the navigation bar. Thanks.
Upvotes: 1
Reputation: 48398
If you are launching the map from within your application, then the easiest way is to use a UINavigationController
in your app. This will build in the navigation bar with functioning back button for you.
If you are launching the Google Maps app, then you are exiting (or moving to background) your app. There is no going back from this. The user will need to exit Google Maps and return to your app manually by pushing the home button and re-selecting your app.
Upvotes: 2