【发布时间】:2014-03-11 20:48:30
【问题描述】:
我正在尝试让我的应用程序打开苹果地图应用程序并提取地址。我试过这个:
- (IBAction)openInMaps:(id)sender {
NSString *addressString = @"http://maps.apple.com/?q=1 Infinite Loop, Cupertino, CA";
NSURL *url = [NSURL URLWithString:addressString];
[[UIApplication sharedApplication] openURL:url];
}
还有这个:
- (IBAction)openInMaps:(id)sender {
NSString *addressString = @"http://maps.apple.com/?q=1_Infinite_Loop,_Cupertino,_CA";
NSURL *url = [NSURL URLWithString:addressString];
[[UIApplication sharedApplication] openURL:url];
}
但按钮的行为就像它没有钩住一样。但这确实有效:
- (IBAction)openInMaps:(id)sender {
NSString *addressString = @"http://maps.apple.com/?q=Cupertino,CA";
NSURL *url = [NSURL URLWithString:addressString];
[[UIApplication sharedApplication] openURL:url];
}
因此,只要它们是空间,它就不起作用。我怎样才能打开这个地址?
【问题讨论】:
-
谢谢,我什至不知道那里有...我去看看
-
我去吧:NSString *addressString = [NSString stringWithFormat:@"maps.apple.com/?q=1+Infinite+Loop,+Cupertino,+CA"];
-
不要不必要地使用
stringWithFormat:。直接分配字符串即可。
标签: ios iphone map street-address apple-maps