【问题标题】:iOS Options when opening maps app by pressing a UIButton?通过按 UIButton 打开地图应用程序时的 iOS 选项?
【发布时间】:2013-10-29 16:41:37
【问题描述】:

我有一个简单的按钮,当按下它时会将您重定向到 IOS 7 中的本地地图应用程序。我目前正在使用 maps.google.com 网址方式,它将您定向到 safari 应用程序。

我的问题是,我如何让手机询问你打开指定地址的地图应用程序,在 safari、谷歌地图、苹果地图或手机上的任何其他应用程序之间进行选择?地址是普通地址,例如英国伦敦。谢谢!

【问题讨论】:

    标签: ios objective-c google-maps uibutton maps


    【解决方案1】:

    我建议您使用自定义 URL,如下所示:

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

    苹果地图

    要打开 Apple 内置地图,请使用以下解决方案: Programmatically open Maps app in iOS 6

    谷歌地图

    如果你想打开官方谷歌地图应用,你可以使用自定义 URL Scheme:https://developers.google.com/maps/documentation/ios/urlscheme,像这样:

    if ([[UIApplication sharedApplication] canOpenURL:
         [NSURL URLWithString:@"comgooglemaps://"]]) {
      [[UIApplication sharedApplication] openURL:
       [NSURL URLWithString:@"comgooglemaps://?center=40.765819,-73.975866&zoom=14&views=traffic"]];
    } else {
      NSLog(@"Can't use comgooglemaps://");
    }
    

    如何提示用户选择?

    我建议你使用 UIActionSheet:https://developer.apple.com/library/ios/documentation/uikit/reference/UIActionSheet_Class/Reference/Reference.html

    【讨论】:

      【解决方案2】:

      查看这段代码:

      NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@",addressString];
      NSString *escaped = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
      [[UIApplication sharedApplication] openURL:[NSURL URLWithString:escaped]];  
      

      【讨论】:

        猜你喜欢
        • 2016-01-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-07-31
        • 1970-01-01
        • 1970-01-01
        • 2014-11-06
        相关资源
        最近更新 更多