如何使用我的ios应用程序中的指示打开Apple地图应用程序
我的目的是从ios应用程序打开地图应用程序和方向,我能够打开地图应用程序,但它没有显示方向,我编写了如下代码
NSString *mystr=[[NSString alloc] initWithFormat:@"http://maps.apple.com/maps?saddr=Current+Location&daddr=Newyork"]; NSURL *myurl=[[NSURL alloc] initWithString:mystr]; [[UIApplication sharedApplication] openURL:myurl];
任何人都可以帮我解释如何将参数传递给这个url和其他任何一个?
如果您的意思是根据两点将用户带到地图应用程序,那么您可以这样做:
创建一个如下所示的NSURL:
NSURL *URL = [NSURL URLWithString:@"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f"];
您可以适当地插入起始地址和目的地(lat。和long。)。 告诉您的应用程序打开URL
[[UIApplication sharedApplication] openURL:URL];
它应该自动带你到地图应用程序!
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(self.location.latitude,self.location.longitude); //create MKMapItem out of coordinates MKPlacemark* placeMark = [[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil]; MKMapItem* destination = [[MKMapItem alloc] initWithPlacemark:placeMark]; if([destination respondsToSelector:@selector(openInMapsWithLaunchOptions:)]) { //using iOS6 native maps app if(_mode == 1) { [destination openInMapsWithLaunchOptions:@{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeWalking}]; } if(_mode == 2) { [destination openInMapsWithLaunchOptions:@{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving}]; } if(_mode == 3) { [destination openInMapsWithLaunchOptions:@{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeTransit}]; } } else{ //using iOS 5 which has the Google Maps application NSString* url = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=Current+Location&daddr=%f,%f", self.location.latitude, self.location.longitude]; [[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]]; }
- AFJSONRequestOperation数组填充,但不能NSLog成功块外的内容
- 在embedded的UIWebView中指定HTTP引用
- iOS:在特定时间调用方法
- 缺less本地化的屏幕截图在iTunes上的错误
- 在使用OpenInfunction的应用程序中,无法通过webbrowser打开docx文件
- CLLocationManager geo-fencing / startMonitoringForRegion:vs. startMonitoringForSignificantLocationChanges:与10分钟的startUpdating调用
- 不区分大小写的数组search
- 我可以着色(黑色)UIKeyboard吗? 如果是这样,怎么样?
- 如何显示日历,而不是在iPhone中使用UIDatePicker?