简体   繁体   English

在Google Maps iPhone应用程序中创建后退按钮

[英]Creating a back button in a Google Maps iPhone app

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? 如何创建后退按钮?

If you are launching the map from within your application , then the easiest way is to use a UINavigationController in your app. 如果要从应用程序内部启动地图,那么最简单的方法是在应用程序中使用UINavigationController 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. 如果要启动Google Maps应用程序,则说明您正在退出(或移至后台)该应用程序。 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. 用户需要通过按下主页按钮并重新选择您的应用程序来退出Google Maps并手动返回到您的应用程序。

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 : 更好的方法是不使用openURL因为它将退出您的应用程序,而是使用UIWebView来查看页面并将其推入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. 这是假设您已经在导航控制器中拥有要从中推入的视图。

You can take a view with navigation bar and a uiwebview. 您可以使用导航栏和uiwebview进行查看。 And put a back button on the navigation bar. 并在导航栏上放置一个后退按钮。 Thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM