iPhone SDK 6 Launching maps with voice navigation directions(iPhone SDK 6 启动带有语音导航方向的地图)
问题描述
我正在尝试从我的 iPhone SDK 应用程序启动地图应用程序.现在我可以启动带有路线的地图应用程序,但它会转到路线概览,并且不使用 Siri 和语音导航来提供转弯路线.
I am trying to launch the maps app from my iPhone SDK app. Right now I can launch the maps app with directions but it goes to an overview of the directions and doesn't use Siri and the voice navigation to give turn by turn directions.
目前我有一个启动此代码的按钮...
currently I have a button that launches this code...
NSString *address = viewedObject.addressFull;
NSString *url = [NSString stringWithFormat: @"http://maps.apple.com/maps?saddr=%f,%f&daddr=%@", here.latitude, here.longitude, [address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
推荐答案
iOS 6 提供了一种启动地图的新方法,使用 MKMapItem
中的 openMapsWithItems:
.这是我使用的一个片段,它提供从当前位置到所提供坐标的步行或驾车路线:
With iOS 6 there's a new way to launch maps, using openMapsWithItems:
in MKMapItem
. Here's a snippet that I use that provides walking or driving directions from current location to the provided coordinates:
// iOS 6.0+ only
MKPlacemark* destPlace = [[[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil] autorelease];
MKMapItem* destMapItem = [[[MKMapItem alloc] initWithPlacemark:destPlace] autorelease]; destMapItem.name = stationItem.title;
NSArray* mapItems = [[[NSArray alloc] initWithObjects: destMapItem, nil] autorelease];
NSDictionary* options = [NSDictionary dictionaryWithObjectsAndKeys:
walking ? MKLaunchOptionsDirectionsModeWalking : MKLaunchOptionsDirectionsModeDriving,
MKLaunchOptionsDirectionsModeKey, nil];
[MKMapItem openMapsWithItems:mapItems launchOptions:options];
按照您的方式,如果在 iOS 6 之前的设备上运行,您仍然需要这样做,您需要在 URL 中包含 dirflg
以请求步行或驾车路线:
The way you are doing it, which you still have to do if running on pre-iOS 6 devices, you need to include the dirflg
in the URL to request walking or driving directions:
// pre iOS 6 code
NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f&dirflg=%c",
currentLocation.coordinate.latitude,
currentLocation.coordinate.longitude,
destination.coordinate.latitude,
destination.coordinate.longitude,
walking ? 'w' : 'd'];
这篇关于iPhone SDK 6 启动带有语音导航方向的地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:iPhone SDK 6 启动带有语音导航方向的地图
基础教程推荐
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01