2013-10-21 17 views
1

我有一個簡單的按鈕,在按下時將您重定向到IOS 7中的本地地圖應用程序。我目前使用maps.google.com url方式,它將您引導至Safari瀏覽器應用程序。通過按UIButton打開地圖應用程序時的iOS選項?

我的問題是,我該如何讓手機詢問您打開指定地址的哪個地圖應用程序,以便在Safari,Google地圖,蘋果地圖或手機上的任何其他應用程序之間進行選擇?地址是正常的,例如倫敦,英國。謝謝!

回答

2

我建議你使用自定義的網址,如:

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

蘋果地圖

爲了打開蘋果的內置地圖中使用此解決方案: Programmatically open Maps app in iOS 6

谷歌地圖

如果你想開官方谷歌地圖應用,你可以使用自定義URL方案: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://"); 
} 

如何提示用戶使用的choise?

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

1

退房這段代碼:

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

你可能想在這裏設置代碼的格式。 。 。 – remudada

相關問題