我使用这段代码来启动谷歌地图。
-(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]];
}
当我点击按钮,谷歌地图加载。这个动作是在我的应用程序的中间。如何创建后退按钮?
更好的方法是不使用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];
这里假设你已经在导航控制器中有了推送的视图
如果你是从你的应用程序中启动地图,那么最简单的方法是在你的应用程序中使用UINavigationController
。这将在导航栏中为你构建功能返回按钮。
如果你正在启动谷歌地图应用程序,那么你正在退出(或移动到后台)你的应用程序。没有回头路。用户将需要退出谷歌地图,并通过按home键重新选择你的应用程序手动返回到你的应用程序。
你可以用导航栏和uiwebview来创建一个视图。在导航栏上放一个后退按钮。谢谢。