2013-01-08 117 views
1

我試圖這樣做是爲了推出谷歌地圖iOS版應用在我的應用程序中打開谷歌地圖:無法在iOS應用程序

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

但是,應用程序不啓動谷歌地圖iOS版的。我確實安裝了Google Maps iOS。

我很想念在這裏?

有人可以幫我嗎?

謝謝。

+0

請問,當你鍵入相同的URL進入Safari瀏覽器的地址欄中工作的呢? –

+0

不,它在Safari的地址欄中不起作用。我在[這裏](https://developers.google.com/maps/documentation/ios/urlscheme) – tranvutuan

+0

這是有趣的,貼上網址,在Safari工作正常,我下面的教程。您是否可能將iOS 5地圖應用與官方Google Maps iOS應用混淆? https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=4&cad=rja&ved=0CFYQFjAD&url=https%3A%2F%2Fitunes.apple.com%2Fus%2Fapp%2Fgoogle-maps% 2Fid585027354%3Fmt%3D8&EI = 80vsUJ7DE6XZigLpvYHwBg與USG = AFQjCNEMo8V21rKG52EDBal5WJ0CoFLoHQ&SIG2 = NGWtZnlNmkDI9Ivt26sikQ與BVM = bv.1357316858,d.cGE –

回答

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]; 
} 
0

你需要包括comgooglemaps URL方案到項目的Info.plist。我建議檢查Localide。它可以幫助您輕鬆打開Goog​​le Maps,Waze,Apple Maps,Transit App,Citymapper和Navigon。

相關問題