无法在iOS应用中打开Goog​​le地图

时间:2013-01-08 16:30:51

标签: ios iphone objective-c google-maps viewdidload

我正在尝试通过以下方式在我的应用程序中启动Google Maps iOS应用程序:

- (void)viewDidLoad
{
    [super viewDidLoad];        
    self.title                  =   @"Google Map";
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:
                                                @"comgooglemaps://?center=40.765819,-73.975866&zoom=14&views=traffic"]];
}

但是,该应用根本不启动Google地图iOS。我安装了谷歌地图iOS。

我在这里失踪了什么?

有人可以帮帮我吗?

感谢。

2 个答案:

答案 0 :(得分:1)

试试这个

 CLLocationCoordinate2D coordinate = COORDINATE;

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

    NSString *daddr = [NSString stringWithFormat:@"%g,%g",coordinate.latitude, coordinate.longitude];

    NSString *urlString = nil;

    BOOL showQuery = YES;
    if (showQuery) {
        // Query
        urlString = [NSString stringWithFormat:@"comgooglemaps://?q=%@",daddr];
    } else {
        // Directions
        urlString = [NSString stringWithFormat:@"comgooglemaps://?saddr=&daddr=%@", daddr];
    }

    NSURL *url = [NSURL URLWithString:urlString];
    [[UIApplication sharedApplication] openURL:url];
}

答案 1 :(得分:0)

您需要在项目Info.plist中加入comgooglemaps网址方案。我建议您查看Localide。它可以帮助您轻松打开Goog​​le地图,Waze,Apple地图,Transit App,Citymapper和Navigon。